首页 > 其他 > 详细

那些常用的git命令

时间:2021-06-10 14:03:06      阅读:24      评论:0      收藏:0      [点我收藏+]

一、本地项目上传git

git remote add origin http://git.xxxxx.git

git add .

git commit -m "提交的啥,描述一下"

git push -u origin master

 

二、第一次push的时候一般会遇到如下报错:

这种错误的主要原因是你的远程仓库的内容有改动但是你本地并没有拉取最新的代码所以会报错

$ git push origin master

To https://github.com/xxxxx.git

 ! [rejected]        master -> master (non-fast-forward)

error: failed to push some refs to ‘https://github.com/xxxxx.git‘

hint: Updates were rejected because the tip of your current branch is behind

hint: its remote counterpart. Integrate the remote changes (e.g.

hint: ‘git pull ...‘) before pushing again.

hint: See the ‘Note about fast-forwards‘ in ‘git push --help‘ for details.

解决方法

首先:

 git pull origin master --allow-unrelated-histories

然后建议做完上一步之后再重新:

git add .

git commit -m ‘提交的啥,描述一下

git push origin master

三、git pull 错分支恢复到原来的版本操作

git reflog 

git reset --hard HEAD@{n}

四、git 撤回push (慎用!!!)

1git log 查看提交记录
2git reset --soft <版本号>
重置至指定版本的提交
可通过git log再次查看提交记录,确认是否撤回
注:git reset --soft <版本号>命令只会退回本地提交记录,远程此时还未撤回
3git push <remotename> <commit SHA>:<remotebranchname> --force

  • <remotename> 远程仓库名,默认为origin
  • <commit SHA> 提交的唯一码
  • <remotebranchname> 远程分支名

将指定commit记录push至远程,完成撤回远程push记录

五、git 打标签

1.创建新tag 1.0.1

git tag -a 1.0.1 -m "发布1.0.1版本"

2.提到远程

git push origin 1.0.1

3.删除本地tag

git tag -d 1.0.1

4.删除tag提到远程

git push origin :refs/tags/1.0.1

 

 

再遇到继续补充....

那些常用的git命令

原文:https://www.cnblogs.com/huijihuijidahuiji/p/14870530.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!