Using Git how do I find changes between local and remote

前端 未结 11 1247
感情败类
感情败类 2020-11-29 15:16

Here are two different questions but I think they are related.

  1. When using Git, how do I find which changes I have committed locally, but haven\'t yet pushed

相关标签:
11条回答
  • 2020-11-29 15:41

    I would do

    $ git fetch --dry-run
    

    for hg incoming and

    $ git push --dry-run
    

    for hg outgoing.

    0 讨论(0)
  • 2020-11-29 15:43

    Starting with Git 1.7.0, there is a special syntax that allows you to generically refer to the upstream branch: @{u} or @{upstream}.

    To mimic hg incoming:

    git log ..@{u}
    

    To mimic hg outgoing:

    git log @{u}..
    

    I use the following incoming and outgoing aliases to make the above easier to use:

    git config --global alias.incoming '!git remote update -p; git log ..@{u}'
    git config --global alias.outgoing 'log @{u}..'
    
    0 讨论(0)
  • 2020-11-29 15:43

    When the "git log" and @{u} answers initially gave me "unknown revision" errors, I tried out Chris/romkyns suggestion of git push --dry-run.

    You will get an output such as "5905..4878 master->master". 5905 is the latest commit that the remote has and commits through (and including) 4878 will be applied to the remote.

    You can then use 5905..4878 as arguments to several other git commands to get more details:

    git diff 5905..4878 # Gives full code changes in diff style
    
    git log --online 5905..4878 # Displays each commit's comment
    
    0 讨论(0)
  • 2020-11-29 15:44

    There's also this, for comparing all branches:

    git log --branches --not --remotes=origin
    

    This is what the git log man page says about this:

    Shows all commits that are in any of local branches but not in any of remote tracking branches for origin (what you have that origin doesn’t).

    The above is for outgoing. For incoming, just swap:

    git log --remotes=origin --not --branches
    
    0 讨论(0)
  • 2020-11-29 15:45

    Not a full answer but git fetch will pull the remote repo and not do a merge. You can then do a

    git diff master origin/master

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