预览 Git 推送
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2176278/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Preview a Git push
提问by Marcus
How can I see which commits are actuallygoing 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.
据我所知,每当我从远程存储库中提取 master 时,即使它们是空的,也可能会生成提交。
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?
我知道将要推送什么,尽管这也显示了我已经推送的一些提交。有没有办法只显示将要推送的新内容?
回答by Greg Bacon
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
记住origin/master
是一个引用,它指向origin
最后一次拉取时命名的远程主分支的头部,因此您可以使用诸如
$ git log origin/master..master
You could use git-preview-push
below that comments on the output of git push --dry-run --porcelain
:
您可以git-preview-push
在下面使用对输出的评论git push --dry-run --porcelain
:
#! /usr/bin/env perl
use warnings;
use strict;
die "Usage: $ git preview-push /tmp/bare master
To /tmp/bare
270f8e6bec7af9b2509710eb1ae986a8e97068ec baz
4c3d1e89f5d6b0d493c9d0c7a06420d6b2eb5af7 bar
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 "[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}..
: 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 "function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)//'
}
function gd2 {
echo branch \(\) has these commits and \(\) does not
git log .. --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
}
: $refspec rejected:\n", $_;
}
elsif ($flag eq "=") {
print "##代码##: $refspec up-to-date\n";
}
if ($summary =~ /^[0-9a-f]+\.\.[0-9a-f]+$/) {
system("git log --pretty=oneline $summary") == 0
or warn "##代码##: git log exited " . ($? >> 8);
}
elsif ($summary eq "[new branch]") {
print "##代码##: $refspec creates a new branch.\n";
}
}
Example usage:
用法示例:
##代码##回答by William Morgan
I wrote a tool to do this called git wtf: https://github.com/michaelklishin/git-wtf. Colors and everything!
我编写了一个名为 git wtf 的工具来执行此操作:https: //github.com/michaelklishin/git-wtf。颜色和一切!
As a bonus, it will also show you the relationship between a feature branch and an integration branch.
作为奖励,它还将向您展示功能分支和集成分支之间的关系。
回答by michael
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:
我已将以下别名添加到我的 ~/.gitconfig 中,以显示将合并的内容(在拉取期间)、将推送的内容以及与远程进行 diff 的别名:
##代码##回答by Clintm
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:
如果你把它放到你的 Bash 配置文件中,你将能够运行 grin(Git 远程传入)和 grout(Git 远程传出)来查看原始主节点传入和传出的提交的差异:
##代码##