2016-12-07 12 views
1

我有以下的分支,其中的A是當前活躍的分支:的底墊git的快捷方式,併合並

*A C 
|/
B 

通常情況下,我想變基CA然後合併成CA。到目前爲止,我正在使用單個命令:

git checkout C 
git rebase A 
git checkout A 
git merge C 

# and optional to clean up no longer needed branches 
git branch -d C 
git push origin :C 

在一個命令中執行此操作的簡單方法是什麼?有沒有「git-way」或者我必須依賴shell腳本?

+0

我想你必須使用shell腳本只是有點像這樣http://stackoverflow.com/questions/18860696/syntax-for-git-aliases-with-multiple-commands或這個http:///stackoverflow.com/questions/7534184/git-alias-multiple-commands-and-parameters,但如果rebase導致任何衝突發生,那麼你可能在合併時遇到問題。 – Deep

回答

1

對於程序像這些我通常設置別名:

git config --global alias.rebmerge '!git checkout C && git rebase A && ...' 

,或者如果你想接受參數:

git config --global alias.rebmerge '!f() { git rebase checkout $1 && git rebase $2 && ... }; f' 

,然後就打電話

git rebmerge A B C 
+0

你能否解釋一下'!f(){...}? – 23tux

+0

我知道有些人使用'hub'有類似的快捷方式,但我從來沒有嘗試過https://github.com/github/hub – pedrorijo91

+2

@gusto''!f(){...}'這裏,' !表示shell腳本,'!f(){..}'是一個以'$ 1','$ 2'和'$ 3'爲參數訪問'A','B'&'C'的函數。 –