我的提交历史记录是
A->B->C(head)
如果我想恢复B
而不会丢失版本C
。
(使所有数据与B
)
(但B和C是合并提交)
A->B->C->B(head)
我使用git flow
来开发我的项目
我想恢复为6450851e7a51f868da414467b42b0c072718f5b9
并执行以下命令但出错。
我怎么能得到它?
(develop)$ git revert 6450851e7a51f868da414467b42b0c072718f5b9
error: Commit 6450851e7a51f868da414467b42b0c072718f5b9 is a merge but no -m option was given.
fatal: revert failed
* f831a96 - (HEAD, tag: 1.1, origin/master, master) Merge branch 'release/1.1' (7 days ago)
|\
| * 277bafc - Release 1.1 (7 days ago)
| * 57a4374 - Merge branch 'feature/add_expired_time_and_restore_sorting_cart_bug' into develop (7 days ago)
| |\
| | * 3866d1d - Remove the larger input field (7 days ago)
| | * 879c12e - Remove the insert new item at first function (7 days ago)
| | * bbd7b2b - remove the change password function (7 days ago)
| | * bc4a6fa - add expired time functionality (7 days ago)
| |/
| * 6450851 - Merge branch 'feature/readable_format' into develop (7 days ago)
| |\
| | * cac4083 - make the line space in table more dense (7 days ago)
答案 0 :(得分:2)
首先,如果你有合并,那么你的提交历史比A->B->C
更复杂。
但是,希望C
不是合并提交。如果这是真的,那么你想运行:
git revert hash-of-commit-C
(git revert
将提交的哈希值撤消,不提交还原为。< / p>
答案 1 :(得分:0)
由于您要还原合并,您需要告诉git合并提交的哪个父项是您要保留的主线:
git revert -m 1 6450851e7a51f868da414467b42b0c072718f5b9
您可以在此处找到更多信息:http://git-scm.com/blog/2010/03/02/undoing-merges.html