2

似乎每当我在一个分支上更改了一些文件,然后想要更改到另一个分支来做一些不同的工作时,这些更改仍然伴随着我。例如,

$ git status
# On branch master
nothing to commit (working directory clean)
~/Sites/sc, kamilski81 (master) 
$ touch FakeFile
~/Sites/sc, kamilski81 (master) 
$ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   FakeFile
nothing added to commit but untracked files present (use "git add" to track)
~/Sites/sc, kamilski81 (master) 
$ git checkout prod
Switched to branch 'prod'
~/Sites/sc, kamilski81 (prod) 
$ git status
# On branch prod
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   FakeFile
nothing added to commit but untracked files present (use "git add" to track)

在这种情况下,为什么当我结帐时 FakeFile 会出现在我身边?如何在多个分支上编辑多个文件而无需签入?还是我只是完全错误地这样做?

4

1 回答 1

2

您可以git stash在分支 A 上使用来保存当前状态并签出另一个分支,然后返回到 A 并使用git stash pop来进入您离开分支的状态。git help stash有关保存本地状态的更多选项,请参阅 git stash ( ) 的帮助页面git stash

于 2012-05-19T18:43:21.250 回答