官术网_书友最值得收藏!

The difference between branches

Checking the difference between branches can show valuable information before merging.

A regular Git diff between two branches will show you all the information, but it can be rather exhausting to sit and look at; maybe you are only interested in one file. Thus, you don't need the long unified diff.

Getting ready

To start with, we decide on two branches, tags, or commits we want to see the diff between. Then, to list files that have changed between these branches, you can use the --name-only flag.

How to do it…

Perform the following steps to see the difference between the branches:

  1. Diff the origin/stable-3.1 with origin/stable-3.2 branch:
    $ git diff --name-only origin/stable-3.1 origin/stable-3.2 org.eclipse.jgit/src/org/eclipse/jgit/transport/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetch
    More output..
    
  2. We are building the command in this pattern, that is, git diff [options] <commit> <commit> <path>. Then, we can diff what we care about while looking into the differences between branches. This is very useful if you are responsible for a subset of the source code, and you wish to diff that area only.
  3. Let's try the same diff between branches, but this time we will diff the entire branches, not just a subdirectory; however, we only want to show the deleted or added files between the branches. This is done by using the --diff-filter=DA and --name-status options. The --name-status option will only show the filenames and the type of change. The --diff-filter=DA option will only show the deleted and added files:
    $ git diff --name-status --diff-filter=DA origin/stable-3.1 origin/stable-3.2
    D org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/Sam
    A org.eclipse.jgit.packaging/org.eclipse.jgit.target/jg
     More output..
    
  4. This shows the files that have been added and deleted while moving from origin/stable-3.1 to origin/stable-3.2:
  5. If we switch the branches around like in the following command, we will get the opposite result.
    $ git diff --name-status --diff-filter=DA origin/stable-3.2 origin/stable-3.1
    A org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/Sam
    D org.eclipse.jgit.packaging/org.eclipse.jgit.target/jg
     More output..
    

Note that the indication letters A and D switched places because now we want to know what happens if we move from origin/stable-3.2 to origin/stable-3.1.

There's more…

There are more options in the help files for Git. Just run git merge --help or git branch --help to see what other options you have. The option I have used and the examples shown are all examples that have given me the edge while working with Git as a release manager and Git mentor at Nokia.

主站蜘蛛池模板: 金秀| 鹰潭市| 泗洪县| 凤凰县| 新兴县| 乌兰察布市| 双江| 开封市| 彰化市| 柳江县| 方山县| 清新县| 阜宁县| 平乐县| 乌什县| 东山县| 晋宁县| 霍林郭勒市| 繁峙县| 富阳市| 英山县| 宜川县| 乌拉特后旗| 蒙城县| 磐石市| 顺昌县| 建昌县| 阳高县| 汽车| 克什克腾旗| 静海县| 南投市| 南康市| 稻城县| 吴桥县| 安徽省| 凌海市| 保康县| 栾城县| 衡山县| 太谷县|