在一个分支上,我做了一些(不记得有多少)git commit
,还有一个git pull
导致合并失败。
我意识到我的本地更改/提交只是愚蠢的,可以丢弃。
为此,我做了:
git checkout master
git branch -D otherbranch
git checkout otherbranch
这似乎不是撤消事情的正确方法——最好的方法是什么?
在一个分支上,我做了一些(不记得有多少)git commit
,还有一个git pull
导致合并失败。
我意识到我的本地更改/提交只是愚蠢的,可以丢弃。
为此,我做了:
git checkout master
git branch -D otherbranch
git checkout otherbranch
这似乎不是撤消事情的正确方法——最好的方法是什么?
你总是可以这样做:
git checkout <branch>
git reset --hard <otherbranch>
这会将分支更改为与另一个分支的状态完全匹配。
如果您只想清除本地更改:
git reset --hard @{u}
在 git 中撤消是使用reset
命令完成的。
回到已知状态通常使用git reset --hard <SHA>
. SHA 是从您想要返回的提交中挑选出来的。
抬头git rebase
http://edgeguides.rubyonrails.org/working_with_javascript_in_rails.html
它允许您编辑提交以及删除它们。
尝试 :
git fetch
git reset --hard origin/<remote_branch>
##this will reset your local branch HEAD to TOT commit
为避免在 git pull 时创建合并提交,请尝试:
git pull --rebase
如果您有本地未合并的提交,正常的 git pull 将创建一个合并提交。