2009-12-02 117 views
2

我已經開始在本地玩git,並且遇到了一個用例,我不知道如何處理。使用git將次要更新複製到另一個分支

我正在研究一個分支的秒殺,但隨後遇到了一個簡單的更正,應該也適用於主。我已經找到了目前最好的是:

git stash 
git checkout master 
//do my correction manually 
git commit -a 
git checkout spike 
git pop 

似乎有點長篇大論,只是一條線,它涉及我做同樣的校正兩次。我不禁感到必須有更好的方式來做到這一點。在你的回答中,還請考慮我不想採取的同一個文件中有其他更改的情況。

回答

1

如果要應用於主控的更改由尖峯分支上的一個完整提交組成,那麼將爲此選擇櫻桃挑選命令。

git stash 
git checkout master 
git cherry-pick <hash> 
git checkout spike 
git stash pop 

如果你只需要提交的一部份,然後使用:

git stash 
git checkout master 
git cherry-pick -n <hash> 
# tinker with the index until it contains the changes that you want to apply to master 
git commit 
git checkout spike 
git stash pop 
+0

剛剛嘗試過,謝謝。有沒有辦法從文件中導入相關的行? – Benjol 2009-12-02 14:20:28

+0

#摘櫻桃-n git的重置頭#後unstage變化 git的添加-p#,選擇您要提交 git的承諾 – 2009-12-02 15:06:37

+0

的評論都跑起來的線。讓我們再試一次。在「git cherry-pick -n」之後:1)「git reset HEAD 」以取消更改。 2)「git add -p」選擇你想要提交的行。 3)「git commit」。 – 2009-12-02 15:08:55

相關問題