Patch not applied after it gets merged

寵の児 提交于 2019-12-22 08:17:09

问题


Using the git flow tool, I created a feature branch (branched off dev), made a bunch of changes, and merged the branch back onto dev.

There is a file which I have modified in the feature branch. I can confirm that the revision (let's call it REV-A) that modifies the file (FILE-A) is present and applied in the feature branch.

However, after the merge, FILE-A is in its original (pre-merge) state on the dev branch. I can see REV-A when I do git log on dev, and if I follow the lines produced by git log --graph, I can trace this commit forward to the merge commit where I merged my feature branch with dev.

However, when I do a git blame of FILE-A, the commit is not there, and the line in question is in its original (pre REV-A commit).

Additionally, git show REV-A | patch -p1 results in the patch being applied cleanly. After that, git diff looks the same as git show REV-A.

What's going on? How is it that a merge introduces a revision into the branch history, but doesn't actually apply it? Are there any other changes from that merge which aren't being applied???


回答1:


If some change hunks appear to be missing from a merge result, the first and in my experience the only question you need to ask is whether git diff shows them as changes between the merge base and the branch tip. Ask it:

git diff $merge^1...$merge^2 -- FILE-A  # `$merge^2` was `feature` as of the merge
                                         # `$merge^1` was `dev`

That three-dot syntax above is specific to diff, everybody at least sometimes wants to see what change hunks merge is seeing for a branch.

If the changes don't appear in the output then those REV_A changes were reverted in some commit between REV_A and the merge, whether by a previous merge (to either branch), in which case you get to ask the same question again about that merge, or directly, by some equivalent of git revert.

If the changes do appear in the output then, since patch applies the hunks cleanly, the changes were manually reverted in that merge.




回答2:


Do you still have the commands you ran? This would be helpful in tracking down where things may have gone awry. I can't help but think that somehow the feature was not 'finished' correctly. Can you confirm you typed git flow feature finish my_feature?

I have simulated a feature with the commands below, but have not encountered the issue you describe. If your steps deviate from what I have below it would be great to compare how, and where.

MBP:git-test acanby (master)$ echo "Original Code" > file.txt
MBP:git-test acanby (master)$ git commit -am "First commit"
MBP:git-test acanby (master)$ git flow init
MBP:git-test acanby (develop)$ git flow feature start my_feature
MBP:git-test acanby (feature/my_feature)$ echo "New feature here" >> file.txt 
MBP:git-test acanby (feature/my_feature)$ git commit -am "Feature change"
MBP:git-test acanby (feature/my_feature)$ git flow feature finish my_feature
MBP:git-test acanby (develop)$ git blame file.txt 
  ^d96c279 (acanby 2015-02-16 20:36:22 +1100 1) Original Code
  62a38725 (acanby 2015-02-16 20:38:37 +1100 2) New feature here
MBP:git-test acanby (develop)$ git log --oneline
  62a3872 Feature change
  d96c279 First commit

Using these commands I was able to complete a feature using the git-flow workflow.

If you're after more info about the git-flow workflow (and specifically the commands and what they do), there is a great cheat sheet available here.



来源:https://stackoverflow.com/questions/28418225/patch-not-applied-after-it-gets-merged

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!