1

When I from master branch merge a branch(wxc):

$ git merge wxc
Merge made by the 'recursive' strategy.
 Q2/__init__.py                                                                |   3 +
 Q2/common/GLOBAL_CONST.py                                                     |   8 +--
 Q2/urls.py                                                                    |   7 ---
 .../admin_productconfig_physicalserver/api/paginations.py"                   |   1 +
 .../admin_productconfig_physicalserver/api/serializers.py"                   |  22 ++++++-
 .../admin_productconfig_physicalserver/api/switch_cmd_util.py"               |  31 +---------
 .../admin_productconfig_physicalserver/api/urls.py"                          |   6 ++
 .../admin_productconfig_physicalserver/api/views.py"                         | 133 +++++++++++++++++++++++++++++++++++++++-
 .../admin_productconfig_physicalserver/migrations/0091_mg.py"                |  34 ++++++++++
 .../admin_productconfig_physicalserver/migrations/0092_mgnumber.py"          |  25 ++++++++
 .../migrations/0093_auto_20190902_1249.py"                                         |  19 ++++++
 .../migrations/0094_merge_20190906_0822.py"                                        |  16 +++++
 .../admin_productconfig_physicalserver/models.py"                            |  61 ++++++++++++++++--
 .../admin_usermanage/api/serializers.py"                                     |   2 +-
 .../admin_usermanage/api/views.py"                                           |   4 +-
 15 files changed, 318 insertions(+), 54 deletions(-)
 create mode 100644 "\346\227\227\344\272\221\347\256\241\347\220\206\345\221\230\345\220\216\345\217\260/\344\272\247\345\223\201\351\205\215\347\275\256/qiyun_admin_productconfig_physicalserver/migrations/0091_mg.py"
 create mode 100644 "\346\227\227\344\272\221\347\256\241\347\220\206\345\221\230\345\220\216\345\217\260/\344\272\247\345\223\201\351\205\215\347\275\256/qiyun_admin_productconfig_physicalserver/migrations/0092_mgnumber.py"
 create mode 100644 "\346\227\227\344\272\221\347\256\241\347\220\206\345\221\230\345\220\216\345\217\260/\344\272\247\345\223\201\351\205\215\347\275\256/qiyun_admin_productconfig_physicalserver/migrations/0093_auto_20190902_1249.py"
 create mode 100644 "\346\227\227\344\272\221\347\256\241\347\220\206\345\221\230\345\220\216\345\217\260/\344\272\247\345\223\201\351\205\215\347\275\256/qiyun_admin_productconfig_physicalserver/migrations/0094_merge_20190906_0822.py"

You see there are so many files changes, such as the Q2/__init__.py, Q2/common/GLOBAL_CONST.py, Q2/urls.py and so on:

then I check my master brach's latest two logs:

$ git log -n2
commit b63c3856677916f8008b338c139bd3b00c90593d (HEAD -> master)
Merge: 6b59b80 3e85a8d
Author: dale <dale@gmail.com>
Date:   Wed Sep 18 11:28:25 2019 +0800

    Merge branch 'wxc 20190917-wxc'

commit 3e85a8dfd0270f6fb0f3786b8761038df322890f (remote_repo/wxc, wxc)
Author: dale <dale@gmail.com>
Date:   Tue Sep 17 16:04:54 2019 +0800

    '2019-09-17-wxc-01'

I want to compare the latest two commits' difference:

dale-MBP:Q2 ldl$ git diff 3e85a8df b63c3856
diff --git "a/\346\227\227\344\272\221\347\256\241\347\220\206\345\221\230\345\220\216\345\217\260/\344\272\247\345\223\201\351\205\215\347\275\256/admin_productconfig_physicalserver/api/whmcs/views.py" "b/\346\227\227\344\272\221\347\256\241\347\220\206\345\221\230\345\220\216\345\217\260/\344\272\247\345\223\201\351\205\215\347\275\256/admin_productconfig_physicalserver/api/whmcs/views.py"
index ccc1ba3..9fac902 100644
--- "a/\346\227\227\344\272\221\347\256\241\347\220\206\345\221\230\345\220\216\345\217\260/\344\272\247\345\223\201\351\205\215\347\275\256/admin_productconfig_physicalserver/api/whmcs/views.py"
+++ "b/\346\227\227\344\272\221\347\256\241\347\220\206\345\221\230\345\220\216\345\217\260/\344\272\247\345\223\201\351\205\215\347\275\256/admin_productconfig_physicalserver/api/whmcs/views.py"
@@ -74,8 +74,11 @@ class WHMCSPhysicalServerIPMIManagementAPIView(APIView):

             if whmcs_site not in [
                 "www.44.hk",
+                "44.hk",
                 "www.44.com",
-                "www.44.net"
+                "44.com",
+                "www.44.net",
+                "44.net"
             ]:
                 return Response(status=HTTP_400_BAD_REQUEST, data="error")

@@ -100,6 +103,8 @@ class WHMCSPhysicalServerIPMIManagementAPIView(APIView):
             physical_server_name = request.data.get('physical_server_name')
             action = request.data.get('action')

+            physical_server_name = str(physical_server_name).split("/")[0]
+
             if not physical_server_name or not action:
                 return Response(data="invalid request data", status=HTTP_400_BAD_REQUEST)

you see there only compare one file(admin_productconfig_physicalserver/api/whmcs/views.py), why there do not compare the other files? and the other question is the admin_productconfig_physicalserver/api/whmcs/views.py did not exist in the merge file changed list:

 Q2/__init__.py                                                                |   3 +
 Q2/common/GLOBAL_CONST.py                                                     |   8 +--
 Q2/urls.py                                                                    |   7 ---
 .../admin_productconfig_physicalserver/api/paginations.py"                   |   1 +
 .../admin_productconfig_physicalserver/api/serializers.py"                   |  22 ++++++-
 .../admin_productconfig_physicalserver/api/switch_cmd_util.py"               |  31 +---------
 .../admin_productconfig_physicalserver/api/urls.py"                          |   6 ++
 .../admin_productconfig_physicalserver/api/views.py"                         | 133 +++++++++++++++++++++++++++++++++++++++-
 .../admin_productconfig_physicalserver/migrations/0091_mg.py"                |  34 ++++++++++
 .../admin_productconfig_physicalserver/migrations/0092_mgnumber.py"          |  25 ++++++++
 .../migrations/0093_auto_20190902_1249.py"                                         |  19 ++++++
 .../migrations/0094_merge_20190906_0822.py"                                        |  16 +++++
 .../admin_productconfig_physicalserver/models.py"                            |  61 ++++++++++++++++--
 .../admin_usermanage/api/serializers.py"                                     |   2 +-
 .../admin_usermanage/api/views.py"                                           |   4 +-
 15 files changed, 318 insertions(+), 54 deletions(-)
 create mode 100644 "\346\227\227\344\272\221\347\256\241\347\220\206\345\221\230\345\220\216\345\217\260/\344\272\247\345\223\201\351\205\215\347\275\256/qiyun_admin_productconfig_physicalserver/migrations/0091_mg.py"
 create mode 100644 "\346\227\227\344\272\221\347\256\241\347\220\206\345\221\230\345\220\216\345\217\260/\344\272\247\345\223\201\351\205\215\347\275\256/qiyun_admin_productconfig_physicalserver/migrations/0092_mgnumber.py"
 create mode 100644 "\346\227\227\344\272\221\347\256\241\347\220\206\345\221\230\345\220\216\345\217\260/\344\272\247\345\223\201\351\205\215\347\275\256/qiyun_admin_productconfig_physicalserver/migrations/0093_auto_20190902_1249.py"
 create mode 100644 "\346\227\227\344\272\221\347\256\241\347\220\206\345\221\230\345\220\216\345\217\260/\344\272\247\345\223\201\351\205\215\347\275\256/qiyun_admin_productconfig_physicalserver/migrations/0094_merge_20190906_0822.py"
user7693832
  • 6,119
  • 19
  • 63
  • 114

2 Answers2

2

When you run git diff 3e85a8df b63c3856, you are not looking at the consolidated differences between the two branches. Instead, you're looking at last change made in one of the two parent branches (whichever one happens to contain the most recent change).

This is because the merge commit (b63c3856) is only there to document the merge by capturing the two parent commits and a log message. From the git-merge description:

Then "git merge topic" will replay the changes made on the topic branch since it diverged from master (i.e., E) until its current commit (C) on top of master, and record the result in a new commit along with the names of the two parent commits and a log message from the user describing the changes.

The key thing to note is "replay the changes". All the individual commits from each branch are preserved.

In your git log output, note the Merge field in the output describing the merge commit:

Merge: 6b59b80 3e85a8d

Those are the commit hashes of the last two commits from each branch before the merge. You can use the the following command to show the diff between the branches:

git diff 6b59b80...3e85a8d

From the git diff documentation:

git diff [<options>] <commit>...<commit> [--] [<path>…​]

This form is to view the changes on the branch containing and up to the second <commit<, starting at a common ancestor of both .

It might also be illustrative to look at the git log output as a graph:

$ git log --graph --oneline --all

Alternatively, if you had used the --squash flag when merging, then the behavior would have matched what you expected. From the git-merge --squash flag documentation (emphasis mine):

Produce the working tree and index state as if a real merge happened (except for the merge information), but do not actually make a commit, move the HEAD, or record $GIT_DIR/MERGE_HEAD (to cause the next git commit command to create a merge commit). This allows you to create a single commit on top of the current branch whose effect is the same as merging another branch (or more in case of an octopus).

chuckx
  • 6,484
  • 1
  • 22
  • 23
1

A merge commit records the combined changes from the branch(es) merged, along with references to the commits at the tips of what is merged.

Condensed from man git-merge:

Given:

      A---B---C topic
     /
D---E---F---G master

...merging topic into master will give:

      A---B---C topic
     /         \
D---E---F---G---H master

Commit H, the merge commit, records the result of merging topic into master. Its first parent will be G (the commit right before the merge on master). Its second parent will be C (the last commit on topic).

The commit that shows in your log under the merge commit is the second parent of the merge commit, i.e. the last commit of the branch you merged (C in the above example). To diff the master branch to its state before the merge (G in the above example), diff against the last commit in master before the merge. This will be the first parent.

git diff master^1 master

As a shorthand, you may leave out the 1 as it is implied:

git diff master^ master

More info on specifying revisions at man gitrevisions.

jsageryd
  • 4,234
  • 21
  • 34