Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git shows differences in files, but won't merge them

Tags:

git

merge

diff

I'm kind of stumped here. Git appears is both telling me that

  1. There are differences between my current branch and the remote branch, and
  2. There are no differences between my current branch and the remote branch

One of these is a lie (or more likely, I'm misunderstanding this scenario). What's up with this??

(~/hbb.vm) debian $ git diff ..stage/master --name-only
sites/all/libraries/attachment_email/attachment_email.php
sites/all/modules/redirect/redirect.module
sites/all/modules/redirect/redirect.test
sites/all/themes/HBB/css/elements.css
sites/all/themes/HBB/templates/node--enterprise_blog.tpl.php

(~/hbb.vm) debian $ git merge stage/master
Already up-to-date.
like image 427
doub1ejack Avatar asked Jan 21 '26 16:01

doub1ejack


2 Answers

The merge command is telling you that your current branch contains all of the commits from the stage/master branch, but not the reverse. It is likely that your current branch contains changes which aren't in stage/master and it is those changes which are being reflected in your diff command.

 a-b----c
    \
     d--e

With the above repository if I have e checked out, trying to merge b will correctly state that things are up to date. But asking for differences between my current state and that same point, it's likely that differences will be present (not guaranteed, e could revert the changes from d or both e and d could be empty commits).

BTW, your diff command is somewhat incorrect. The .. in front of the branch name causes that to be interpreted as a range of commits (equivalent to HEAD..stage/master), but diff operates on individual commits rather than ranges. This is a somewhat common mistake so diff has been adjusted to somewhat allow for it, but it can still give misleading results. In this case it will show changes reversed from what you'd likely expect showing the changes needed to go from your current state to stage/master rather than the changes that took place to bring the state from stage/master to the state reflected by the tip of your current branch. The latter is more likely be be what you were expecting.

like image 159
qqx Avatar answered Jan 24 '26 06:01

qqx


You're correct in assuming 1.: There're differences between where you're at (HEAD) and stage/master.

Any of these tell you this:

  1. git diff ..stage/master
  2. git diff HEAD..stage/master
  3. git diff stage/master..
  4. git diff stage/master..HEAD

1 is short-hand for 2, and 3 for 4. 3 is just the reverse diff of 1.

git diff stage/master that @qqx mentioned will further tell you of any differences between your working-tree and stage/master. (Compared to 1 or 3, you'll also see uncommitted changes.)

You're incorrect in thinking 2.: There are no differences between HEAD and stage/master.

Rather, git merge stage/master is telling you that there're no commits in stage/master that aren't already in (or merged to) HEAD.

This might also tell you this:

  • git log ...stage/master --cherry-pick

And this might tell you of the commits that're causing the diff after you've merged stage/master:

  • git log stage/master... --cherry-pick
like image 43
antak Avatar answered Jan 24 '26 07:01

antak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!