我在我的存储库中得到了一些提交:
喜欢:
A - Added Feature A
B - Removed Feature B
C - Redesigned Feature C
D - Added Feature D
E - Added Feature D
Run Code Online (Sandbox Code Playgroud)
E是我最近的提交.现在我想摆脱我使用功能C所做的更改,但我希望保持更改添加D和E.
我希望你能帮助我.
谢谢
Ben*_*anc 26
互动变基是你的朋友!
正如其他人所说:
$ git rebase -i HEAD~5
Run Code Online (Sandbox Code Playgroud)
... -i交互式标志在哪里,HEAD~5意味着包括交互式rebase中的最后5次提交.
由于发布上述内容而导致编辑,请查看打开文件中的注释:
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
Run Code Online (Sandbox Code Playgroud)
对你而言,关键是如果你在这里删除一行,那么COMMIT将会丢失.
因此,删除引用您想要删除,保存和关闭的提交的行,git将处理其余的(您可能必须修复一些冲突,具体取决于提交的性质和您尝试删除的还原).
重要的是要注意,如果你已经推送了你的代码而其他人已经把它拉了下来,那么上面的代码将无法正常工作,因为下次有人检查你的分支机构时会提醒他们.交互式rebase删除提交到没有记录的程度,因此其他克隆不知道它们已被删除.下次他们推送时,他们会尝试重新设置它们,因为本地克隆"看到"原点没有你删除的对象(提交).
如果您只想"摆脱更改"(在问题体中指定)而不是实际"删除提交"(如标题中所指定的),一个简单的选择是添加新提交,完全相反先前的提交做了什么.
这不是万无一失的,它可能会因为改变而导致冲突,但它不会改变历史记录,允许您记录逆转及其原因,并与其他工作副本一起使用.
git revert 是用于制作一组提交的邪恶双胞胎的工具.
| 归档时间: |
|
| 查看次数: |
13781 次 |
| 最近记录: |