如何在不使用Git的情况下同时在多个分支上工作?

时间:2012-05-19 18:38:39

标签: git

似乎每当我更改一个分支上的某些文件,然后想要更改为另一个分支来执行某些不同的工作时,这些更改仍然随我而来。例如,

$ 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会随身携带?如何编辑多个分支上的多个文件而不必检查它们?或者我只是完全错误地做到了这一点?

1 个答案:

答案 0 :(得分:2)

您可以在分支A上使用git stash来保存当前状态并检出另一个分支,返回到A并使用git stash pop进入您离开分支的状态。有关使用git help stash

保存本地状态的更多选项,请参阅git stash(git stash)的帮助页面