Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

git - GitHub does not recognize changes from a reverted pull request

I'm working on a Git branch called bug-fix-1, which I created based off integration branch. There was another branch bug-fix-2 which was merged into integration branch and then we reverted the changes (all were done on Github).

Now when I put up a new pull request to merge my bug-fix-1 into integration, I expect to see the changes which I pulled from bug-fix-2. But no, I can't see any of them, the pull request only show the changes I made on bug-fix-1.

Any solution on how do I pull in the changes from bug-fix-2 into my branch and merge them together to integration ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is an interesting feature of Git, and not such a bad one once you realize what is happening.

Git tracks commits by commit hash, and from the history hot-fix-2 is already present. Git also knows that the reversion has been applied, but it doesn't really see it as backing out the original commit. Instead, it's just another commit that happens to apply the same diff in reverse, and it has it's own commit hash too.

In order to allow Git to see the changes, you have one of several choices:

  1. Revert the revert. As weird as it sounds, it works. This says to introduce a new commit that contains the reverse diff. That commit is not present on the integration branch, and so Git will see it as a change to be brought in.

  2. You can cherry pick the original commit, but you'll need a special option:

    git cherry-pick --keep-redundant-commits COMMIT_HASH
    

    where COMMIT_HASH introduces the original bug fix.

There are other ways to help do this too, but they're a bit more complicated and involve using git rebase. I think the above techniques are probably the most straight-forward.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...