0

伙计,这个 git 东西肯定是个难啃的骨头!

所以我有这个分支:

a--b--c--d - 分支

我在这里要做的是返回提交'b'并继续工作和提交。但我既不想重新分支,也不想松散'c'和'd'提交。我一直在阅读有关此 git revert 的内容,但无法完全理解它的价值。

帮助!

4

1 回答 1

1

As stated before, there is no way to do this without creating a new branch (unless you want to get into some risky business with the 'ref' history and commits that haven't been garbage collected, which isn't worth it in this scenario when a simple solution exists).

Create a new branch to store the commits you want to save, but don't want in your mybranch.

git checkout -b newBranch

Go back to mybranch in order to remove commits 'c' and 'd'.

git checkout mybranch

git reset --hard b

Now you can continue your work in mybranch from commit 'b'. Later, if you want to bring commits 'c' and 'd' back into mybranch, you can just do a git merge newBranch from mybranch.

于 2014-01-06T01:16:11.940 回答