Using Git how do I find changes between local and remote

前端 未结 11 1300
感情败类
感情败类 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:25

    Incoming commits across all branches can be shown with the following approach.

    The command git fetch-diff becomes available by adding an executable called git-fetch-diff to your PATH, containing:

    #!/bin/bash
    
    set -e
    
    # get hashes before fetch
    old_hashes=$(git log --all --no-color --pretty=format:"%H")
    
    # perform the fetch
    git fetch
    
    # get hashes after fetch
    new_hashes=$(git log --all --no-color --pretty=format:"%H")
    
    # get the difference
    added_hashes=$(comm -1 -3 <(echo "$old_hashes") <(echo "$new_hashes"))
    
    # print added hashes
    [ ! -z "$added_hashes" ] && echo "$added_hashes" | git log --stdin --no-walk --oneline
    

    Commit hashes are compared before and after the fetch. The difference is piped back to git log for pretty printing. The appearance of the printed log can be further tuned to your liking with arguments such as --pretty= and --graph.

    Note: You might want to cap how far git log will go back in time depending on how much a bash variable can hold on your system, or for performance reasons. This can be done by adding the argument --max-count=.

提交回复
热议问题