Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GIT diff giving me different feedback than git merge

Tags:

git

when I run

git diff FETCH_HEAD

it lists a load of expected changes, since I fetched the updated version from my remote.

BUT....

when I run

git merge FETCH_HEAD

it tells me all is up to date!!

Where am I going wrong?

like image 683
Mild Fuzz Avatar asked Sep 07 '26 17:09

Mild Fuzz


1 Answers

Why is FETCH_HEAD different from the HEAD, after a merge?

A merge creates a new commit, containing all the changes from the original HEAD, now ORIG_HEAD and the FETCH_HEAD. This means that if your original HEAD contained changes not contained in FETCH_HEAD, then the new (merged) HEAD will be different from FETCH_HEAD since it contains those commits as well.

Thing to check

It's possible your current branch is already up-to-date with the FETCH_HEAD from a previous fetch, for the above reason, or for another reason.

To check this, get the sha (hex number) from your fetch head as follows:

git log -1 FETCH_HEAD
commit bec5aadef68a5d29c9d523358a0189b86cad4c82
Author: Alex Brown <alex@XXX>
Date:   Tue Nov 16 10:05:19 2010 +0000

    weather report

and copy the first 6 digits of the FETCH_HEAD: bec5aa

next, search for this sha in the ancestry of your head

git log HEAD | grep "commit bec5aa" -A 5

commit bec5aadef68a5d29c9d523358a0189b86cad4c82
Author: Alex Brown <alex@XXX>
Date:   Tue Nov 16 10:05:19 2010 +0000

    weather report

if this returns anything but blank, the FETCH_HEAD has already been merged. Any differences you see are in the current HEAD, which may be the merged HEAD (or a descendant).

*Example to demonstrate this"

cd /tmp
mkdir 1
cd 1
git init
echo "Woo" > a.txt
git add a.txt 
git commit -m "first commit"
cd ..
git clone 1 2
cd 1
echo "Its nice today" >> a.txt
git commit -a -m "weather report"
cd ..
ls
cd 2
ls
echo "Like peas in a pod" > b.txt
git add b.txt 
git commit -m "sayings"
git fetch
git diff FETCH_HEAD
git merge FETCH_HEAD
git diff FETCH_HEAD
like image 200
Alex Brown Avatar answered Sep 11 '26 10:09

Alex Brown



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!