当我在分支时,如何将未提交的更改放入分支 TEST master
?
问问题
46014 次
4 回答
195
您也可以创建一个新分支并通过执行以下操作切换到它:
git checkout -b new_branch
git add .
我一直使用它,因为我总是忘记在开始编辑代码之前启动一个新分支。
于 2010-12-17T00:31:54.887 回答
151
您可以只签出到测试分支然后提交。移动到另一个分支时,您不会丢失未提交的更改。
假设你在 master 分支:
git checkout test
git add .
git add deletedFile1
git add deletedFile2
...
git commit -m "My Custom Message"
我不太确定已删除的文件,但我猜您使用时不包含它们git add .
于 2009-08-29T14:34:05.337 回答
36
为什么不直接使用 git stash。我认为它像复制粘贴一样直观。
$ 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
stash@{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 ...
于 2012-11-13T17:46:12.713 回答
5
git checkout TEST
git add file1 file2
git commit
于 2009-08-29T14:33:37.210 回答