git 解决ahead behind分叉以及删除远端commit

  • Post author:
  • Post category:其他


  1. 解决ahead / behind

先reset到ahead,然后退回到分叉,再checkout 远端的behind

如果要删除本地的commit, 先到本地的最前端, 然后再用下面的命令

If you want to fix up your latest commit, you can undo the commit, and

unstage the files in it, by doing:

git reset HEAD~1 This will return your repository to its state before

the git add commands that staged the files. Your changes will be in

your working directory. HEAD~1 refers to the commit below the current

tip of the branch.

If you want to uncommit N commits, but keep the code changes in your

working directory:

git reset HEAD~N If you want to get rid of your latest commit, and do

not want to keep the code changes, you can do a “hard” reset.

git reset –hard HEAD~1 Likewise, if you want to discard the last N

commits, and do not want to keep the code changes:

git reset –hard HEAD~N

2.删除远端commit

先退回到正确的local commit然后

git push –force



版权声明:本文为seamanj原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。