开发者

git merge does not merge

开发者 https://www.devze.com 2023-04-12 10:02 出处:网络
I have a master and \"PersonalSite\" branch for a codebase I\'m working on.I have been repeatedly trying to merge the master into the 开发者_运维技巧PersonalSite branch to no avail.

I have a master and "PersonalSite" branch for a codebase I'm working on. I have been repeatedly trying to merge the master into the 开发者_运维技巧PersonalSite branch to no avail.

This time, I thought I had everything straightened out, so I did:

git checkout master
git pull
git checkout PersonalSite
git pull
git merge master

It looked like everything was working, and it listed the set of files I would have expected, but there was a conflict. The conflict was correct and was as expected, so I fixed it, did "git add", "git commit", then "git push". But now, when I look at my git log, it just shows a commit with no code changes but a single conflict.

Now, when I run "git merge master" from the "PersonalSite" branch it says "Already up-to-date." but this clearly is not the case, as none of the changes I tried to merge actually merged. What exactly do I do to get master to actually merge at this point?


By fixing the conflict and committing the merge conflict you've already completed the merge. Git adds merge commits when necessary, it's normal but they don't record anything except that the merge took place and what files were merged if there was a conflict. If you look more closely at your log you'll see there are in fact commits from master.

EDIT: Okay, try this a test. You don't have to use the merge command, you can just pull master into PersonalSite.

git checkout PersonalSite
git pull origin master

See what gives you. If it says up to date then you have merged correctly.

If you merge stuff locally like you did, then you need to ensure the local tracking branches are up to date. Always specify the branch name to pull from,

git pull origin master
git pull origin PersonalSite


I realize that this is an older question now, but I was just having what I believe is the same problem. I couldn't get it resolved with any combination of the commands in other answers, but I did resolve it by running in the branch that I want merges into:

git checkout <desired_branch_name> -- .

So for you:

git checkout master -- .

I found this answer here: git: checkout files from another branch into current branch (don't switch HEAD to the other branch)


Assuming you have actually merged what you meant to merge (which is possible but hard to tell, given your explanation), you still won't see diffs in the output of git log, just the commit messages. Even if you use -p to tell git log to show diffs, the diff for the merge commit will generally be empty, or possibly show conflict resolutions. This is because semantically, only conflict resolutions are part of the merge commit; the other changes are part of other commits.

If you want git log to show you the full effect of merge commits anyway, you can use:

git log -p -m -c

The function of the options:

  • -p directs it to show diffs, not just commit messages;
  • -m tells it to show diffs for merge commits too; and
  • -c tells it to combine the two diffs into one for merge commits

The diff view in gitk will do the same thing.


a merge will not show any changes except your conflict resolutions.

To see the differences on either side of the merge do:

git diff head^..

and

git diff head^2..

for the other side.

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号