简体   繁体   English

git:显示当前合并配置值

[英]git: display current merge config value

Is there a way to display the current merge config option in git without manually specifying the current branch I am in. I am wanting to do something like this: 有没有一种方法可以显示git中的当前merge config选项, 而无需手动指定我所在的当前分支。我想做这样的事情:

$ git cur-merge-val
branch.current.merge = /refs/heads/current

where git cur-merge-val could be some long, complicated series of git commands to which I can make an alias for -- so long as what I personally type on the command line doesn't require typing the current branch I'm in (because that seems redundant since that information should be programmatically accesible somehow). git cur-merge-val可能是一系列冗长而复杂的git命令,我可以为其添加别名-只要我在命令行上亲自键入的内容不需要键入我所在的当前分支(因为这似乎是多余的,因为该信息应以某种方式在程序上可访问)。

Create the following script (eg, call it cur-merge-val.sh and make it executable): 创建以下脚本(例如,将其cur-merge-val.sh并使其可执行):

current=`git status -s -b | head -1 | cut -d' ' -f2`
git config branch.$current.merge

Then, just add the following to your .gitconfig file: 然后,只需将以下内容添加到您的.gitconfig文件中:

[alias] [别名]
cur-merge-val = /path/to/cur-merge-val.sh cur-merge-val = /路径/到/cur-merge-val.sh

I found a solution which: 我找到了一种解决方案:

  1. avoids porcelain commands in favor of plumbing commands 避免使用瓷器命令,而使用管道命令
  2. shows also the current remote config value and all possible merge config values if there are multiple of them. 还显示当前的远程配置值和所有可能的合并配置值(如果有多个)。
  3. avoids having to make another executable file 避免制作另一个可执行文件

see https://stackoverflow.com/a/1593487/10608 for a reference of why I get current branch name the way I do. 请参阅https://stackoverflow.com/a/1593487/10608 ,以获取有关为什么以这种方式获取当前分支名称的参考。

[alias]
    cur-merge-val = !branch_name="$(git symbolic-ref HEAD)" && branch_name=${branch_name##refs/heads/} && git config --get-all branch.$branch_name.remote; git config --get-all branch.$branch_name.merge

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM