當我在分支master
時,如何將未提交的變更提交給分支TEST?將未提交的變更通過Git提交給一個新分支
回答
您可以結帳到測試分支然後提交。移動到另一個分支時,您不會失去無限制的更改。
假如你是在主分支:
git checkout test
git add .
git add deletedFile1
git add deletedFile2
...
git commit -m "My Custom Message"
我真的不知道關於刪除的文件,但我想,當你使用git add .
有時,結帳將失敗,因爲您的更改與該分支發生衝突。您可以嘗試簽出-m進行合併。 – 2010-11-04 14:00:05
刪除的文件可以在您執行'git -u add。'時進行管理。 – 2012-08-17 19:44:37
我試過了,但出現錯誤: 錯誤:您對本地文件的更改將被結帳覆蓋。請在您更改分支之前進行修改或存儲它們。 – ishwr 2013-12-19 11:16:14
git checkout TEST
git add file1 file2
git commit
+1僅用於簡單 – 2012-08-17 19:45:27
你也可以創建一個自己不包括新的分支,並切換到它這樣做:
git checkout -b new_branch
git add .
我用這一切的時候,因爲我總是忘記之前,我開始編輯代碼,開始一個新的分支。
+1最簡單的答案。 – 2012-08-17 19:45:06
與@jouni針對其他答案指出的相同問題 - 如果其他更改與原始更改衝突,則可能會遇到難以將分支合併回主。 IMO這個線程更好地回答了這個問題:http:// stackoverflow。com/questions/556923/git-how-to-merge-my-local-working-changes-into-another-branch – jpwynn 2013-04-20 18:58:30
簡短,甜美而令人放心......「我一直都在用這個......」 – 2013-06-17 16:45:08
爲什麼不使用git存儲。我認爲它更像直接複製粘貼。
$ git branch
develop
* master
feature1
TEST
$
您在當前分支中有一些文件需要移動。
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: awesome.py
#
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
#
# modified: linez.py
#
$
$ git stash
Saved working directory and index state \
"WIP on master: 934beef added the index file"
HEAD is now at 934beef added the index file
(To restore them type "git stash apply")
$
$ git status
# On branch master
nothing to commit (working directory clean)
$
$
$ git stash list
[email protected]{0}: WIP on master: 934beef ...great changes
$
移到其他分支。
$ git checkout TEST
並申請
$ git stash apply
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
#
# modified: awesome.py
# modified: linez.py
#
我也很喜歡git stash
因爲我用git flow
,當你想完成一個特性分支,而在工作目錄中仍然有變化,這抱怨。
就像@Mike Bethany一樣,這一直髮生在我身上,因爲我在解決一個新問題的同時忘記了我還在另一個分支上。所以你可以存儲你的工作,git flow feature finish...
,和git stash apply
到新的git flow feature start ...
分支。
'git stash'是我處理未提交更改的首選方式。當你認爲它是剪切和粘貼的時候,這當然是一種直觀的方法。 – 2013-01-22 13:41:17
這對我來說似乎是一個很好的方法。它工作沒有問題。 – 2014-05-01 09:04:58
不知道你可以做到這一點,它很好地工作。感覺有點比其他方法更直觀。 – glaucon 2014-08-14 04:55:13
- 1. Subversion將未提交的更改提交到一個新分支
- 2. Git:簽出一個保留未提交更改的分支
- 3. Git - 創建一個新的分支並只提交給這個分支?
- 4. git只推送一個分支提交
- 5. zsh - 顯示git分支是否有提交過的提交
- 6. GIT中移動從主未提交更改至新分支
- 7. Git + Gerrit跨分支提交?
- 8. Git遠程分支提交
- 9. git合併重新提交提交到另一個提交?
- 10. Git - 推送新提交併忽略未提交的更改
- 11. git rebase分支後推新提交
- 12. 每個分支的Git提交鉤子
- 13. 將最近一次提交的提交消息更新到本地分支
- 14. Git - 從以前的提交和拆分提交歷史分支
- 15. git:合併兩個分支並提交提交
- 16. 如何撤消提交併將更改提交到Git中的其他分支?
- 17. git cherry將一個提交到另一個分支
- 18. 將本地Git提交到git-svn的一個提交中
- 19. 通過分支名稱\ id與git api獲取git提交
- 20. 將新分支的Git更改爲源分支的較舊提交
- 21. Git:同時提交多個分支
- 22. Git分支差異到一個新的提交
- 23. 移動git的分支之間的未提交更改
- 24. Git:提交部分更改
- 25. 合併大的git提交,將它分成主分支上的小提交
- 26. Git在第一次提交時刪除分支時在遠程分支上提交提交
- 27. Bazaar綁定分支提交和更新
- 28. Git:提交新文件後,我不能提交,因爲»分支最新«-message
- 29. 將提交從一個分支移動到另一個分支
- 30. Git合併中間提交的分支
另請參閱:http://stackoverflow.com/questions/2944469/how-to-commit-my-current-change-to-a-different-branch-in-git – 2010-11-04 13:59:05