更改git status比较的分支 [英] Change the branch that git status compares with

查看:514
本文介绍了更改git status比较的分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我输入 git status 我看到

你的分支是最新的'origin / master' 。


如果我有多个远程服务器,并且想要与远程调用功能进行比较,那么我输入的git状态仍然与原始数据进行比较。有没有办法,当我输入 git status 我看到

您的分支是最新的'功能/ master'。


也可以做一些类似git status的功能 - >比较本地master与feature / master,或者git status feature1 feature2 - > compare本地主人与功能1 /主和功能2 /主?



如果不可能的话,什么是最好的方式来看看有多少提交/与两个不同的地方分支)?我不想要 git diff ,因为这给了我太多的细节。



在此先感谢。

解决方案

松散地基于,显示所有分支的git前后信息,这里是一个shell脚本,它应该允许你有一个前面......后面。 ..message for any two commitits:

  file ./ahead.sh:
#!/ bin / bash
left = $ 1
right = $ 2

leftahead =`git rev-list --count $ right .. $ left`
rightahead =`git rev-list --count $ left .. $ right`

echo$ left(ahead $ leftahead)|($ rightahead后面)$ right

  $ ./ahead.sh HEAD origin /掌握
HEAD(提前7)| (在0之后)origin / master






git rev-list $ left .. $ right 显示从(但不包括) $ left 和 $ right 高达 $ right



git rev-list --count $ left .. $ right 将简单地计算这个序列中的提交数量。



使用 git rev-list --count $ left .. $ right git rev-list --count $ right .. $ left ,你得到提前/落后计数(什么是前面和后面取决于哪一个提交作为参考)




有关已修改文件的列表(à git status ),您可以使用 git diff --name-status

 #!/ bin / bash 
left = $ 1
right = $ 2

leftahead =`git rev-list --count $ right .. $ left`
rightahead =`git rev-list --count $ left .. $ right`

echo$ left(ahead $ leftahead)| (在$ rightahead后面)$ right
git diff --name-status $ right $ left



<如果 git diff --name-status 产生的时间太长了,那么更新 输出时,寻呼机将会启动,并且隐藏最初的前面的行。这是一个修复,使用 - no-pager 选项:

 #!/ bin / bash 

function displayStatus {
left = $ 1
right = $ 2

leftahead =`git rev-list --count $ right .. $ left`
rightahead =`git rev-list - 计数$ left .. $ right`

echo$ left(ahead $ leftahead)| (在$ rightahead后面)$ right
git --no-pager diff --name-status $ right $ left
}

displayStatus $ 1 $ 2 | less


When I type git status I see
Your branch is up-to-date with 'origin/master'.

What if I have more than one remote, and I want to compare with a remote call 'feature', I type git status it still compare with origin. Is there a way that when I type git status I see
Your branch is up-to-date with 'feature/master'.?

Also is it possible to do something like git status feature -> compare local master with feature/master, or git status feature1 feature2 -> compare local master with feature1/master and feature2/master?

If not possible, what is the best way to see how many commits ahead/behind with certain remotes or branches(even with two different local branches)? I don't want git diff because that gives me too many details

Thanks in advance.

解决方案

Loosely based on Show git ahead and behind info for all branches, including remotes, here is a shell script which should allow you to have a "ahead ... behind ..." message for any two commits :

file ./ahead.sh :
#!/bin/bash
left=$1
right=$2

leftahead=`git rev-list --count $right..$left`
rightahead=`git rev-list --count $left..$right`

echo "$left (ahead $leftahead) | (behind $rightahead) $right"

usage :

$ ./ahead.sh HEAD origin/master
HEAD (ahead 7) | (behind 0) origin/master


git rev-list $left..$right displays the sequnce of commits starting from (but not including) the common ancestor for $left and $right up to $right.

git rev-list --count $left..$right will simply count the number of commits in this sequence.

Using both git rev-list --count $left..$right and git rev-list --count $right..$left, you get the ahead/behind counts (what is "ahead" and "behind" depends on which commit serves as reference).


For a list of modified files (à la git status), you can use git diff --name-status :

#!/bin/bash
left=$1
right=$2

leftahead=`git rev-list --count $right..$left`
rightahead=`git rev-list --count $left..$right`

echo "$left (ahead $leftahead) | (behind $rightahead) $right"
git diff --name-status $right $left

update

If git diff --name-status produces too long an output, the pager will kick in, and hide the initial ahead | behind line. Here is a fix, using the --no-pager option :

#!/bin/bash

function displayStatus {
  left=$1
  right=$2

  leftahead=`git rev-list --count $right..$left`
  rightahead=`git rev-list --count $left..$right`

  echo "$left (ahead $leftahead) | (behind $rightahead) $right"
  git --no-pager diff --name-status $right $left
}

displayStatus $1 $2 | less

这篇关于更改git status比较的分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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