为什么不使用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 ...
分支。