What Git teams will display content that is present only in a branch whose commits are completely merged with master? Some content may be missing in master, because, for example, some merge operations may have used the strategy ours, ignoring the contents of the branch (i.e. git merge --strategy ours branch).
I found that normal Git comparison operations do not give the desired result.
For example, the team git diff master..branchand git diff branch..masterdo not work, because they show differences in the content of the master. (How can I change this command to omit the changes to master?)
The command git diff master...branchalso does not work, because all the commits on branchpreviously were combined with the master in several merge operations over time.
Example:
- Create a file
a.txtin a branch master. - Add line 1 to
a.txtthe branch master. - Create a branch
branch. - Add line 2 to
a.txtthe branch branch. - Go to the branch
master. - Add line 2 to
a.txtthe branch master. - Merge branch
branchwith masterusing strategy ours. This is similar to the "dummy" merge, which merges all commits on branchto master, but discards their contents. - Compare branches
masterand branch.
Sequence of commands:
derek@derek-lubuntu:~/Projects$ git init test
Initialized empty Git repository in /home/derek/Projects/test/.git/
derek@derek-lubuntu:~/Projects$ cd test
derek@derek-lubuntu:~/Projects/test$ touch a.txt
derek@derek-lubuntu:~/Projects/test$ git add a.txt
derek@derek-lubuntu:~/Projects/test$ git commit
[master (root-commit) 6a36816] Added a.txt.
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 a.txt
derek@derek-lubuntu:~/Projects/test$ echo "Line 1 from master." >> a.txt
derek@derek-lubuntu:~/Projects/test$ git commit -a
[master c9ebf16] Added line 1.
1 file changed, 1 insertion(+)
derek@derek-lubuntu:~/Projects/test$ git checkout -b branch
Switched to a new branch 'branch'
derek@derek-lubuntu:~/Projects/test$ echo "Line 2 from branch." >> a.txt
derek@derek-lubuntu:~/Projects/test$ git commit -a
[branch 8a142dd] Added line 2.
1 file changed, 1 insertion(+)
derek@derek-lubuntu:~/Projects/test$ cat a.txt
Line 1 from master.
Line 2 from branch.
derek@derek-lubuntu:~/Projects/test$ git checkout master
Switched to branch 'master'
derek@derek-lubuntu:~/Projects/test$ echo "Line 2 from master." >> a.txt
derek@derek-lubuntu:~/Projects/test$ git commit -a
[master d496cc7] Added line 2.
1 file changed, 1 insertion(+)
derek@derek-lubuntu:~/Projects/test$ git merge
Merge made by the 'ours' strategy.
derek@derek-lubuntu:~/Projects/test$ git merge branch
Already up-to-date.
derek@derek-lubuntu:~/Projects/test$ git diff master..branch
diff
index f773e76..5dae91a 100644
+++ b/a.txt
@@ -1,2 +1,2 @@
Line 1 from master.
-Line 2 from master.
+Line 2 from branch.
derek@derek-lubuntu:~/Projects/test$ git diff branch..master
diff
index 5dae91a..f773e76 100644
+++ b/a.txt
@@ -1,2 +1,2 @@
Line 1 from master.
-Line 2 from branch.
+Line 2 from master.
derek@derek-lubuntu:~/Projects/test$ git diff master...branch
derek@derek-lubuntu:~/Projects/test$ git diff branch...master
diff
index 5dae91a..f773e76 100644
+++ b/a.txt
@@ -1,2 +1,2 @@
Line 1 from master.
-Line 2 from branch.
+Line 2 from master.
Git "+ Line 2 ". "+ Line 2 ". "-Line 2 ".?