Preview a Git push

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, commits are likely to be generated, even if they're empty.

This causes the local master to be 'forward' even if there is really nothing to push.

Now, if I try (from master):

git cherry origin master

I have an idea of what's going to be pushed, though this also display some commits that I've already pushed. Is there a way to display only the new content that's going to be pushed?


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 refspecn" 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-daten";
  }
  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

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.


我在〜/ .gitconfig中添加了以下别名,以显示合并的内容(在拉取过程中),将要推送的内容以及与远程对象进行比较的别名:

[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}..
链接地址: http://www.djcxy.com/p/31744.html

上一篇: 列表Git提交没有推送到原点

下一篇: 预览Git推送