Showing which files have changed between two revisions

I want to merge two branches that have been separated for a while and wanted to know which files have been modified.

Came across this link: http://linux.yyz.us/git-howto.html which was quite useful.

The tools to compare branches I've come across are:

  • git diff master..branch
  • git log master..branch
  • git shortlog master..branch
  • Was wondering if there's something like "git status master..branch" to only see those files that are different between the two branches.

    Without creating a new tool, I think this is the closest you can get to do that now (which of course will show repeats if a file was modified more than once):

  • git diff master..branch | grep "^diff"
  • Was wondering if there's something I missed...


    To compare the current branch against master

    $ git diff --name-status master
    

    To compare any pair of branches

    $ git diff --name-status firstbranch..yourBranchName
    

    That should do what you need, if I understand you correctly.


    Try

    $ git diff --stat --color master..branchName
    

    This will give you more info about each change, while still using the same number of lines.

    You can also flip the branches to get an even clearer picture of the difference if you were to merge the other way:

    $ git diff --stat --color branchName..master
    

    Also keep in mind that git has cheap and easy branching. If I think a merge could be problematic I create a branch for the merge. So if master has the changes I want to merge in and ba is my branch that needs the code from master I might do the following:

    git checkout ba
    git checkout -b ba-merge
    git merge master
    .... review new code and fix conflicts....
    git commit
    git checkout ba
    git merge ba-merge
    git branch -d ba-merge
    git merge master
    

    End result is that I got to try out the merge on a throw-away branch before screwing with my branch. If I get my self tangled up I can just delete the ba-merge branch and start over.

    链接地址: http://www.djcxy.com/p/4434.html

    上一篇: 如何获取所有的git分支?

    下一篇: 显示哪些文件在两个修订之间发生了变化