简体   繁体   English

通过其他目录中的bash脚本执行git命令

[英]execute git commands through bash script in other directory

is there a way to execute git commands in a bash script, add the changed files, commit it with a comment then push them to the server where the bash file isn't in the directory of the repository? 有没有办法在bash脚本中执行git命令,添加更改的文件,用注释提交它然后将它们推送到bash文件不在存储库目录中的服务器?

this is what I have, and everything works except the commit, 这就是我所拥有的,除了提交之外,一切正常,

cd /home/repos
git add file.txt

echo "comment: "
read input_varible

git commit -m '$input_varible'
git push origin master

when the commit line executes I get this error, 当提交行执行时,我收到此错误,

error: bad index file sha1 signature
fatal: index file corrupt

but when i do everything in the terminal it works fine. 但是当我在终端中做所有事情时它工作正常。

and yes i have tried to reset the indexes by using this command but it doesnt work 是的,我试图通过使用此命令重置索引,但它不起作用

    rm -f .git/index
    git reset

I am working on a linux if that helps 如果有帮助的话,我正在开发一个linux

Yes this is possible. 是的,这是可能的。 I am doing it by adding an alias to the script in my ~/.bash_profile file. 我是通过在~/.bash_profile文件中为脚本添加别名来实现的。

Since you're adding an alias, do not forget to reload your terminal. 由于您要添加别名,请不要忘记重新加载终端。 Oh yeah, and you don't need all of the cd /path/to/directory stuff since you need to launch your command inside the repository directory. 哦,是的,你不需要所有的cd /path/to/directory东西,因为你需要在存储库目录中启动你的命令。

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

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