當我在分支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. Git - 創建一個新的分支並只提交給這個分支?
- 6. 的Git分支VS提交
- 7. 在提交之前將提交提交到新分支
- 8. git只推送一個分支提交
- 9. zsh - 顯示git分支是否有提交過的提交
- 10. git的過濾分支提交
- 11. git分支撤消提交
- 12. Git遠程分支提交
- 13. Git - 提交出主分支
- 14. Git + Gerrit跨分支提交?
- 15. Git合併分支提交
- 16. GIT中移動從主未提交更改至新分支
- 17. 移動未提交更改到一個新的分支
- 18. Git:將提交的一部分應用到另一個分支
- 19. git合併重新提交提交到另一個提交?
- 20. git將本地提交的更改移至新分支並按
- 21. git rebase分支後推新提交
- 22. Git - 推送新提交併忽略未提交的更改
- 23. 提交到一個新的Subversion分支
- 24. git:將當前分支中當前未提交的工作提交到新分支
- 25. Git - 將未提交的更改推送到以前的提交
- 26. 每個分支的Git提交鉤子
- 27. 將git分支提交到SVN
- 28. GIT中替換其間與另一分支提交提交
- 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