dby*_*rne 1587
删除最近的提交,保留您已完成的工作:
git reset --soft HEAD~1
Run Code Online (Sandbox Code Playgroud)
删除最近的提交,破坏您已完成的工作:
git reset --hard HEAD~1
Run Code Online (Sandbox Code Playgroud)
Ash*_*ous 65
我不知道为什么我找到的最佳答案只是在评论中!(由丹妮丝以86票赞成)
git reset --hard origin
Run Code Online (Sandbox Code Playgroud)
此命令将使本地存储库与远程存储库同步,从而消除您对本地存储库所做的所有更改。
Von*_*onC 54
不要删除它:只需一次提交即可git cherry-pick.
但是如果你在错误的分支上有几个提交,那就是git rebase --onto闪耀的地方:
假设你有这个:
x--x--x--x <-- master
\
-y--y--m--m <- y branch, with commits which should have been on master
Run Code Online (Sandbox Code Playgroud)
,然后你可以标记master并移动到你想要的位置:
git checkout master
git branch tmp
git checkout y
git branch -f master
x--x--x--x <-- tmp
\
-y--y--m--m <- y branch, master branch
Run Code Online (Sandbox Code Playgroud)
,重置y分支应该在哪里:
git checkout y
git reset --hard HEAD~2 # ~1 in your case,
# or ~n, n = number of commits to cancel
x--x--x--x <-- tmp
\
-y--y--m--m <- master branch
^
|
-- y branch
Run Code Online (Sandbox Code Playgroud)
,最后移动你的提交(重新申请,实际上是新的提交)
git rebase --onto tmp y master
git branch -D tmp
x--x--x--x--m'--m' <-- master
\
-y--y <- y branch
Run Code Online (Sandbox Code Playgroud)
如果要将该提交移动到另一个分支,请获取有问题的提交的SHA
git rev-parse HEAD
Run Code Online (Sandbox Code Playgroud)
然后切换当前分支
git checkout other-branch
Run Code Online (Sandbox Code Playgroud)
并cherry-pick承诺other-branch
git cherry-pick <sha-of-the-commit>
Run Code Online (Sandbox Code Playgroud)
以下命令对我有用,所有本地提交的更改都被删除,本地被重置为与远程源/主分支相同。
git reset --hard 原点
| 归档时间: |
|
| 查看次数: |
480177 次 |
| 最近记录: |