Windows 为多个git命令创建别名
我通常在git的“工作”分支上使用这些命令Windows 为多个git命令创建别名,windows,git,command-line,git-bash,Windows,Git,Command Line,Git Bash,我通常在git的“工作”分支上使用这些命令 git commit -a -m "blah! blah!" git checkout master git merge work git checkout work 我听说过git别名。是否可以通过别名或其他方式将所有这些命令组合成一个命令。除了注释中发布的命令的答案外,还可以放置一个名为“git foo”的可执行shell脚本(例如)在路径的某个地方并使用git foo访问它,就像它是一个本地git命令一样 如果别名的逻辑对于配置文件中的一行来说
git commit -a -m "blah! blah!"
git checkout master
git merge work
git checkout work
我听说过git别名。是否可以通过别名或其他方式将所有这些命令组合成一个命令。除了注释中发布的命令的答案外,还可以放置一个名为“
git foo
”的可执行shell脚本(例如)在路径的某个地方
并使用git foo
访问它,就像它是一个本地git命令一样
如果别名的逻辑对于配置文件中的一行来说太长,这可能很有用
例如:
$ cat > ~/bin/git-foo
#!/bin/bash
echo "Foo: $1"
^C
$ chmod +x ~/bin/git-foo
$ git foo test
Foo: test
#!/bin/bash
git commit -a -m "$1"
git checkout master
git merge work
git checkout work
您还可以将以下内容添加到shell.rc文件中: gmm将所有给定的分支与您当前所在的分支合并 调用:gmm branch1要合并branch2要合并
gmm () {
src=`git branch --no-color | grep "*" | cut -f 2`
for i in $@
do
git checkout $i
git merge $src
done
git checkout $src
}
正如@Will Vousden所建议的,可以编写一个shell脚本来实现这一点。例如:
$ cat > ~/bin/git-foo
#!/bin/bash
echo "Foo: $1"
^C
$ chmod +x ~/bin/git-foo
$ git foo test
Foo: test
#!/bin/bash
git commit -a -m "$1"
git checkout master
git merge work
git checkout work
你会称之为:
$ git-commit.sh "Commit message in quotes"
但是,如果存在合并冲突,这种方法(或您自己的别名)很容易失败:
$ git-commit.sh "Commit message in quotes"
[work 1a6e17f] Commit message in quotes
1 file changed, 1 insertion(+), 1 deletion(-)
Switched to branch 'master'
Auto-merging file.txt
CONFLICT (content): Merge conflict in file.txt
Automatic merge failed; fix conflicts and then commit the result.
file.txt: needs merge
error: you need to resolve your current index first
在主分支中留下未解决的合并冲突
您可能会在脚本中添加一些逻辑,以检测(并可能解决)此类问题,但这听起来比只运行四个单独的命令要复杂得多 对不起,我是windows用户,对git不熟悉。那么你能告诉我你的例子在做什么吗