自动应用“git update-index --chmod = + x”到可执行文件 [英] Automatically apply "git update-index --chmod=+x" to executable files
问题描述
我经常将bash脚本添加到我的git存储库,并且脚本在 git add
之前的linux文件系统中具有可执行权限。但在将添加的文件推送到远程存储库并拉入另一个位置之后,这些文件显示出不可执行的权限。似乎有两种方法可以解决问题:
1。 chmod u + x $ script
git commit -am修复脚本权限...再次...
或
2。 git update-index --chmod = + x $ script
不是每次修改权限,有没有办法让git在 git add
期间简单地查看脚本的文件权限,并认识到嘿,这是一个可执行文件!并直接使用可执行权限将其添加到存储库中?
有几种方法可以做到这一点。
- Git别名
- Bash别名
- 甚至可以将bash和git别名组合在一起
$ b
-
Git别名
-
打开你的git config:
vim〜/ .gitconfig
-
在其中添加别名部分(如果不存在):
[别名]
addscr =!sh -c'if [[$ {0:-3} ==.sh]];然后git update-index --chmod = + x $ 0; git add $ 0'
-
-
bash别名
-
编辑您的bash配置文件:
vim〜/ .bashrc
-
在文件末尾添加:
function gitadd(){
if [[{{1:-3} == .sh]]
然后git update-index --chmod = + x $ 1
fi
git add $ 1
}
别名gitadd ='gitadd'
-
-
结合git和bash别名
-
编辑您的bash配置文件:
vim〜/ .bashrc
-
添加到文件末尾:
$ b函数checkShellFile(){
return $ {1:-3} ==.sh
}
别名gitadd ='checkShellFile? git addsrcipt$ 1:&& git添加$ 1'
-
编辑您的git配置文件:
$ bvim〜/ .gitconfig
-
它(如果一个不存在):
$ b[别名]
addscript =! sh -c'git update-index --chmod = + x $ 0&& git add $ 0'
-
以上均未经过测试
I frequently add bash scripts to my git repository, and the scripts have executable permissions in the linux filesystem prior to the git add
. But after pushing the added files to a remote repository and pulling in another location, the files show up with non-executable permissions. There seem to be two ways to correct the problem:
1. chmod u+x $script
git commit -am "fixing the script permissions... again..."
or
2. git update-index --chmod=+x $script
Instead of fixing up the permissions every time, is there a way to have git simply look at the file permissions on the script during git add
, recognize that "hey, this here is an executable file!" and add it to the repository with the exectuable permissions directly?
There are several ways to do that.
- Git aliases
- Bash aliases
- Or even combine bash and git aliases
Git aliases
You can always use bash within your git alias.
Open your git config:
vim ~/.gitconfig
Add an aliases section to it (if one does not exist):
[alias] addscr = !sh -c 'if [[ ${0: -3} == ".sh" ]]; then git update-index --chmod=+x $0; git add $0'
Bash aliases
Edit your bash profile file:
vim ~/.bashrc
Add this at the end of the file:
function gitadd(){ if [[ ${1: -3} == ".sh" ]] then git update-index --chmod=+x $1 fi git add $1 } alias gitadd='gitadd'
Combine git and bash aliases
Edit your bash profile file:
vim ~/.bashrc
Add this to the end of the file:
function checkShellFile(){ return ${1: -3} == ".sh" } alias gitadd='checkShellFile ? git addsrcipt "$1" : && git add "$1"'
Edit your git config file:
vim ~/.gitconfig
Add an aliases section to it (if one does not exist):
[alias] addscript = !sh -c 'git update-index --chmod=+x $0 && git add $0'
None of the above has been tested
这篇关于自动应用“git update-index --chmod = + x”到可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!