简体   繁体   English

使用Shell命令进行Git配置

[英]Git config using shell command

I have a alias that does a short status, parses it with sed then adds the files to the 'assume-unchanged' index of git. 我有一个别名,它的状态很短,用sed解析它,然后将文件添加到git的“假定不变”索引中。

However, the issue seems to be a simple problem with my understanding of escaping single quotes in OS X bash. 但是,根据我对在OS X bash中转义单引号的理解,该问题似乎是一个简单的问题。

irm = !sh -c 'git ignore $(git st --short -u | sed '\''/^ D/s/^ D//g'\'')'  

This is the full line in gitconfig. 这是gitconfig中的完整行。 I can issue the command in the shell (with sh and the quote), but I get bad git config when I try to run it via git irm 我可以在shell中发出命令(带有sh和引号),但是当我尝试通过git irm运行它时,我得到了错误的git config

based on advice below, I have configured this a little differently. 根据以下建议,我对此进行了一些不同的配置。 However, it still doesn't work in gitconfig. 但是,它在gitconfig中仍然不起作用。 So I added this to my ~/.profile 所以我把这个加到我的~/.profile

alias irm="git ignore $(git st --short | grep '^ D' | sed 's/^ D //')"

You should be able to use double quotes, but you'll have to escape them: 您应该能够使用双引号,但是必须转义它们:

irm = !sh -c 'git ignore $(git st --short -u | sed \"s/^ D//\")'

You don't need to select the line since the operation is the same as the selection. 您无需选择该行,因为操作与选择相同。 You may want to use -n and p with sed as Chris suggests in the comment if you only want to output the lines that match and exclude any others. 如果您只想输出匹配并排除其他任何行,则可能要像克里斯在注释中建议的那样将-npsed一起使用。

Also, since the pattern is anchored you don't need the global option. 另外,由于模式是固定的,因此您不需要全局选项。

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

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