我正在学习git。我从 master 分支创建了一个新的 NEW
分支,并在 NEW
中创建了一个新文件。现在,当我切换回 master 时,NEW
中新创建的文件在 master 分支中可见。正常吗?如果是这样,如何 stash master 分支中其他分支的文件。
最佳答案
在您添加它 ( git add <file>
) 并提交它 ( git commit -m 'My new file'
) 之前,您新创建的文件不会被跟踪。这意味着 git 不知道它的索引树中存在它。
所以你所描述的行为是完全可以预料的。这个schema可能会帮助您理解(source)。
尝试以下操作:
git checkout master # start from the master branch
git checkout -b NEW # create and switch onto the NEW branch
echo foo > bar # create a new file
git add bar # track the file
git commit -m 'My new file' # Commit the new file
git checkout master # The file has disappeared from the working directory
关于git - 来自其他分支的文件在 master 分支中可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21453421/