Reputation: 2565
I have really strange situation with git tree at my current project.
At file a.txt
, I did commit id=my_new_contents_commit
that changed it from:
old contents
old contents
old contents
To:
old contents
old contents
old contents
my new contents
Simultaneously (without merging this commit), other team member did some changes. Then he pulled my changes and did merge id=interesting_merge
(he uses some git tool called "tower"). git show
for that merge commit shows something like this:
➤ git show interesting_merge
commit interesting_merge
Merge: some_commit my_commit_with_new_contents_being_there
Author: _
Date: Thu May 16 19:55:27 2013 +0300
Merge branch 'master' of _
Conflicts:
static/css/style.css
So, it seems that there were some conflicts during merge, I'm not sure how they were resolved. What's interesting, is that after this merge, file is in it's older version again. So, if you do
➤ git checkout interesting_merge
➤ cat a.txt
old contents
old contents
old contents
you'll get old contents. How is it possible? How can I see that a.txt was merged in such a strange seemless way?
Thank you!
Upvotes: 1
Views: 144
Reputation: 21972
git show
doesn't show diff for commit with many parents commits, because git doesn't know what of N
diffs (where N
is number of parent commits) it should show.
When you resolve some conflicts by hands, this diff just lives in commit message and nothing more.
How is it possible?
Easy. In this merge commit my new contents
is just removed. You should find it in one of two diffs:
Finally, git diff SHA^!
should be useful.
How it could be done.
Lets say we have 2 commits
$> git log --oneline
30917b9 add my new contents
d6a09ba add a.txt
and the last commit is similar to your
$> git show
commit 30917b94b6e6740cacc854e891d67d29195b98c3
Author: b <a>
Date: Fri May 17 00:29:56 2013 +0400
add my new contents
diff --git a/a.txt b/a.txt
index 3be5d25..af49de6 100644
--- a/a.txt
+++ b/a.txt
@@ -1,3 +1,4 @@
old contents
old contents
old contents
+my new contents
Then someone do changes based on the first commit (d6a09ba
):
commit f6997eae5f40f156897eedfbf058bcf3fe8730b6
Author: b <a>
Date: Fri May 17 00:34:38 2013 +0400
I don't care about new contents
diff --git a/b.txt b/b.txt
new file mode 100644
index 0000000..d099a6a
--- /dev/null
+++ b/b.txt
@@ -0,0 +1 @@
+well, this is a new file
He tried to push it and got reject :[
$> git push origin
To jws:~/test.git
! [rejected] HEAD -> master (non-fast-forward)
Then he pull your commit and made a merge
$> git pull origin master
From jws:~/test
* branch master -> FETCH_HEAD
Merge made by the 'recursive' strategy.
a.txt | 1 +
1 file changed, 1 insertion(+)
this is a commit message like Merge branch 'master' of jws:~/test
. Then he edit file a.txt
, add it to staging with git add a.txt
, add staging to commit with git commit --amend
and voila:
$> git show
commit 51a3f94436cf1a9a763d84acfcf7202f9f2d88ec
Merge: f6997ea 30917b9
Author: b <a>
Date: Fri May 17 00:36:56 2013 +0400
Merge branch 'master' of jws:~/test
Nothing about changes in a.txt
but it is modified as we can see in one of the diffs:
$> git diff 51a3f94436cf1a9a763d84acfcf7202f9f2d88ec^2 51a3f94436cf1a9a763d84acfcf7202f9f2d88ec
diff --git a/a.txt b/a.txt
index af49de6..3be5d25 100644
--- a/a.txt
+++ b/a.txt
@@ -1,4 +1,3 @@
old contents
old contents
old contents
-my new contents
diff --git a/b.txt b/b.txt
new file mode 100644
index 0000000..d099a6a
--- /dev/null
+++ b/b.txt
@@ -0,0 +1 @@
+well, this is a new file
Upvotes: 2