预览Git推送 [英] Preview a Git push

查看:86
本文介绍了预览Git推送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么看到哪些提交实际上被推送到远程存储库?



据我所知,只要我从远程仓库拉主,提交很可能会产生,即使它们是空的。



这导致本地主人是'转发',即使有现在,如果我尝试(从主人):

 <$> 

c $ c> git cherry origin master

我有一个想要推动什么的想法,虽然这还显示我已经推送的一些提交。有没有一种方法可以显示将要推送的新内容? 是一个ref,它指向最后一次拉动的名为 origin 的远程主分支的头部,所以你可以使用这样的命令作为

  $ git log origin / master..master 

你可以在的输出上使用 git-preview-push > git push - -dry-run --porcelain

 #! / usr / bin / env perl 

使用警告;
使用strict;

die用法:$ 0 remote refspec\\\
除非@ARGV == 2;
my($ origin,$ refspec)= @ARGV;
我的@cmd = qw / git push --dry-run --porcelain /;
没有警告'exec';
打开我的$ fh, - | => @cmd,$ origin,$ refspec或死$ 0:exec:$!;
#<标志> \t< from>:< to> \t< summary> (< reason>)
my $ update = qr / ^(。*)\ t#flag(可选)
(\S +):( \S +)\ t#from:到
(。+)#summary
(?:[] \((。+)\))? #理由
$ / x;

,而($ fh>){
next除非我的($ flag,$ from,$ to,$ summary,$ reason)= / $ update /;
if($ flag eq!){
print$ 0:$ refspec rejected:\\\
,$ _;
}
elsif($ flag eq=){
print$ 0:$ refspec up-to-date \\\
;

if($ summary =〜/^[0-9a-f]+\.\.[0-9a-f]+$/){
system( git log --pretty = oneline $ summary)== 0
或警告$ 0:git log exited。 ($?>> 8);
}
elsif($ summary eq[new branch]){
print$ 0:$ refspec创建一个新的分支。\\\
;




$ b

示例用法:

 $ git preview-push / tmp / bare master 
至/ tmp / bare
270f8e6bec7af9b2509710eb1ae986a8e97068ec baz
4c3d1e89f5d6b0d493c9d0c7a06420d6b2eb5af7 bar


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 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

这篇关于预览Git推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆