How do I see the commit differences between branches in git?

后端 未结 10 950
太阳男子
太阳男子 2020-12-04 04:13

I\'m on branch-X and have added a couple more commits on top of it. I want to see all the differences between MASTER and the branch that I am on in terms of commits. I could

相关标签:
10条回答
  • 2020-12-04 04:59

    If you are on Linux, gitg is way to go to do it very quickly and graphically.

    If you insist on command line you can use:

    git log --oneline --decorate
    

    To make git log nicer by default, I typically set these global preferences:

    git config --global log.decorate true
    git config --global log.abbrevCommit true
    
    0 讨论(0)
  • 2020-12-04 05:13

    You can get a really nice, visual output of how your branches differ with this

    git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative master..branch-X
    
    0 讨论(0)
  • 2020-12-04 05:13

    I think it is matter of choice and context.I prefer to use

    git log origin/master..origin/develop --oneline --no-merges
    

    It will display commits in develop which are not in master branch.

    If you want to see which files are actually modified use

    git diff --stat origin/master..origin/develop --no-merges
    

    If you don't specify arguments it will display the full diff. If you want to see visual diff, install meld on linux, or WinMerge on windows. Make sure they are the default difftools .Then use something like

    git difftool -y origin/master..origin/develop --no-merges
    

    In case you want to compare it with current branch. It is more convenient to use HEAD instead of branch name like use:

    git fetch
    git log origin/master..HEAD --oneline --no-merges
    

    It will show you all the commits, about to be merged

    0 讨论(0)
  • 2020-12-04 05:14
    #! /bin/bash
    if ((2==$#)); then
      a=$1
      b=$2
      alog=$(echo $a | tr '/' '-').log
      blog=$(echo $b | tr '/' '-').log
      git log --oneline $a > $alog
      git log --oneline $b > $blog
      diff $alog $blog
    fi
    

    Contributing this because it allows a and b logs to be diff'ed visually, side by side, if you have a visual diff tool. Replace diff command at end with command to start visual diff tool.

    0 讨论(0)
提交回复
热议问题