2013-05-22 100 views
1

我一般使用這些命令的分支「工作」與GIT創建幾個git的別名命令

git commit -a -m "blah! blah!" 
git checkout master 
git merge work 
git checkout work 

我聽說過git的別名。是否有可能通過別名或其他方式將所有這些命令組合成一個。

+1

http://stackoverflow.com/q/7534184/1615903 – 1615903

回答

0

還有答案張貼在評論duplicate question,你也可以把你的PATH地方叫git-foo(例如)一個可執行的shell腳本,並訪問它git foo <args>就好像它是一個本地的Git命令。

如果您的別名的邏輯是在你的配置文件中的一行太長,這非常有用。

例如:

$ cat > ~/bin/git-foo 
#!/bin/bash 
echo "Foo: $1" 
^C 
$ chmod +x ~/bin/git-foo 
$ git foo test 
Foo: test 
+0

對不起,我是一個Windows用戶以及新來的git。那麼你能否告訴我你的例子在做什麼 –

0

您還可以添加以下到您的shell.rc文件:

GMM融合了一個你目前

調用所有給出分支:GMM分支1要合併的分支2要合併...

gmm() { 
     src=`git branch --no-color | grep "*" | cut -f 2` 
     for i in [email protected] 
     do 
       git checkout $i 
       git merge $src 
     done 
     git checkout $src 
} 
0

As @ Will-Vousden sug gests,那麼編寫一個shell腳本就可以做到這一點。例如:

#!/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 

離開你的主分支與一個未解決的合併衝突。

你也許可以添加一些邏輯到腳本檢測 - 和潛在的工作輪 - 這樣的問題,但是這聽起來像更多的工作和努力,不只是爲四個獨立的命令!