【发布时间】:2010-11-24 00:10:00
【问题描述】:
当我在分支 master 时,如何将未提交的更改放入分支 TEST?
【问题讨论】:
当我在分支 master 时,如何将未提交的更改放入分支 TEST?
【问题讨论】:
您也可以创建一个新分支并通过以下方式切换到它:
git checkout -b new_branch
git add .
我一直使用它,因为我总是忘记在开始编辑代码之前启动一个新分支。
【讨论】:
您可以只签出到测试分支然后提交。移动到另一个分支时,您不会丢失未提交的更改。
假设你在 master 分支:
git checkout test
git add .
git add deletedFile1
git add deletedFile2
...
git commit -m "My Custom Message"
我不太确定删除的文件,但我猜当您使用git add .时它们不包括在内
【讨论】:
为什么不直接使用 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 一样,这一直发生在我身上,因为我在处理一个新问题时忘记了我还在另一个分支上。所以你可以stash你的工作,git flow feature finish...和git stash apply到新的git flow feature start ...分支。
【讨论】:
git stash 是我处理未提交更改的首选方式。当您将其视为剪切和粘贴时,这无疑是一种直观的方法。
git stash --include-untracked
git checkout TEST
git add file1 file2
git commit
【讨论】: