Preview a Git push

后端 未结 4 1865
广开言路
广开言路 2020-12-28 12:30

How can I see which commits are actually going to be pushed to a remote repository?

As far as I know, whenever I pull master from the remote repository, com

相关标签:
4条回答
  • Remember origin/master is a ref that points to the head of the master branch on the remote named origin at the last pull, so you could use a command such as

    $ git log origin/master..master
    

    You could use git-preview-push below that comments on the output of git push --dry-run --porcelain:

    #! /usr/bin/env perl
    
    use warnings;
    use strict;
    
    die "Usage: $0 remote refspec\n" unless @ARGV == 2;
    my($origin,$refspec) = @ARGV;
    my @cmd = qw/ git push --dry-run --porcelain /;
    no warnings 'exec';
    open my $fh, "-|" => @cmd, $origin, $refspec or die "$0: exec: $!";
    # <flag> \t <from>:<to> \t <summary> (<reason>)
    my $update = qr/^ (.*)         \t    # flag (optional)
                      (\S+):(\S+)  \t    # from:to
                      (.+)               # summary
                      (?:[ ] \((.+)\))?  # reason
                    $/x;
    
    while (<$fh>) {
      next unless my($flag,$from,$to,$summary,$reason) = /$update/;
      if ($flag eq "!") {
        print "$0: $refspec rejected:\n", $_;
      }
      elsif ($flag eq "=") {
        print "$0: $refspec up-to-date\n";
      }
      if ($summary =~ /^[0-9a-f]+\.\.[0-9a-f]+$/) {
        system("git log --pretty=oneline $summary") == 0
          or warn "$0: git log exited " . ($? >> 8);
      }
      elsif ($summary eq "[new branch]") {
        print "$0: $refspec creates a new branch.\n";
      }
    }
    

    Example usage:

    $ git preview-push /tmp/bare master
    To /tmp/bare
    270f8e6bec7af9b2509710eb1ae986a8e97068ec baz
    4c3d1e89f5d6b0d493c9d0c7a06420d6b2eb5af7 bar
    0 讨论(0)
  • 2020-12-28 12:41

    I wrote a tool to do this called git wtf: https://github.com/michaelklishin/git-wtf. Colors and everything!

    As a bonus, it will also show you the relationship between a feature branch and an integration branch.

    0 讨论(0)
  • 2020-12-28 12:58

    If you drop this into your Bash profile you'll be able to run grin (Git remote incoming) and grout (Git remote outgoing) to see diffs of commits that are incoming and outgoing for origin master:

    function parse_git_branch {
      git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
    }
    
    function gd2 {
        echo branch \($1\) has these commits and \($2\) does not
        git log $2..$1 --no-merges --format='%h | Author:%an | Date:%ad | %s' --date=local
    }
    
    function grin {
        git fetch origin master
        gd2 FETCH_HEAD $(parse_git_branch)
    }
    
    function grout {
        git fetch origin master
        gd2 $(parse_git_branch) FETCH_HEAD
    }
    
    0 讨论(0)
  • 2020-12-28 13:02

    I've added the following aliases to my ~/.gitconfig, to show what would be merged (during a pull), what would be pushed, and an alias to diff against the remote:

    [alias]
            # diff remote branch (e.g., git diff origin/master master)
            difr = "diff @{u}"
    
            # similar to hg incoming/outgoing, showing what would be pulled/pushed
            # use option "-p" to see actual patch
            incoming = "!git remote update -p; git log ..@{u}"
    
            # showing what would be pushed (see also alias difr)
            outgoing = log @{u}..
    
    0 讨论(0)
提交回复
热议问题