如何查看实际将被推送到远程仓库的提交记录?
据我所知,每当我从远程仓库拉取主分支时,提交记录都有可能会生成,即使它们是空的。
这会导致本地的主分支即使没有需要推送的内容也变得“前进”了。
现在,如果我尝试(从主分支):
git cherry origin master
我知道即将被推送的内容是什么,但这也展示了我已经推送过的一些提交。有没有办法只显示即将被推送的新内容?
记住,origin/master
是一个引用,指向上次拉取时远程命名为origin
的主分支的头部,因此您可以使用以下命令:
$ git log origin/master..master
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";
}
}
示例用法:
$ git preview-push /tmp/bare master 到 /tmp/bare 270f8e6bec7af9b2509710eb1ae986a8e97068ec baz 4c3d1e89f5d6b0d493c9d0c7a06420d6b2eb5af7 bar
[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}..
如果您将此内容放入Bash配置文件中,您就可以运行grin(Git远程传入)和grout(Git远程传出),以查看原始主机的传入和传出提交差异:
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
}
git log origin/master..master
就足够了。 - Igor Zevakagit log origin/master..master --oneline --decorate
也不错。 - hIpPy