英文:
git - re-apply changes from a previous commit from same branch like a merge/rebase
问题
在同一个分支上,你想要重新应用在提交 B
中对 foo.cpp
所做的更改,并手动解决冲突,就好像它是一个合并或变基操作。请注意,提交 B
已经在历史记录中,所以你尝试使用 merge
、rebase
或 cherry-pick
失败了,因此提出了这个问题。
如何完成这个操作?
英文:
Say I have a file foo.cpp
tracked by git, which was added in commit A
. Then in commit B
, I have added a big set of changes.
Now later, on the same branch, I have made changes to foo.cpp
again, however it was based on the version of foo.cpp
as it was in commit A
. I would now like to re-apply the changes to it I made it commit B
, and resolve the arising conflicts manually as if it were a merge or a rebase. Note that commit B
is already in the history, so my attempts to use merge
, rebase
, or cherry-pick
have failed, hence this question.
How can this be done?
答案1
得分: 2
添加并提交您现在拥有的内容。将其命名为C。现在仅对文件foo.cpp比较A和B,将该差异导入文件。然后使用git apply
应用该文件。
英文:
Add and commit what you have now. Call it C. Now diff A to B for just the file foo.cpp and pipe that diff into a file. Now git apply
that file.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论