如何查看哪些提交实际上将被推送到远程存储库?
据我所知,每当我从远程存储库中提取master时,即使它们是空的,也可能会生成提交.
即使没有任何东西可以推动,这也会导致本地主人"前进".
现在,如果我尝试(来自主人):
git cherry origin master
Run Code Online (Sandbox Code Playgroud)
我知道将要推动什么,虽然这也显示了我已经推动的一些提交.有没有办法只显示要推送的新内容?
Gre*_*con 25
记住origin/master是一个引用指向origin最后一个pull 命名的远程主分支的头部的ref ,所以你可以使用诸如
$ git log origin/master..master
Run Code Online (Sandbox Code Playgroud)
您可以git-preview-push在下面的输出中使用以下注释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";
}
}
Run Code Online (Sandbox Code Playgroud)
用法示例:
$ git preview-push /tmp/bare master To /tmp/bare 270f8e6bec7af9b2509710eb1ae986a8e97068ec baz 4c3d1e89f5d6b0d493c9d0c7a06420d6b2eb5af7 bar