如何在 git 的分支中添加一个新文件夹而不让该文件夹显示在 master 分支中?
e.g.
git branch myNewBranch
git checkout myNewBranch
mkdir foo
git checkout master
ls
myNewBranch目录也添加到master
最佳答案
仅仅因为你创建了文件夹,git 不会自动启动版本控制它。您创建的文件夹对于 git 是未知的,因此 git 不会触及它。
git init #create repo
touch file1.txt
git add file1.txt
git commit -m 'initial commit'
git branch newBranch
git checkout newBranch
mkdir folder
touch folder/file2.txt
git add folder #tell git we want to track the folder
git commit -m 'second commit'
git checkout master
# folder/file2.txt is not available as expected.
编辑:为了阐明您的示例中的文件夹未添加到 master,它实际上未添加到任何分支。
关于git - 如何在不将新文件夹添加到master的情况下将新文件夹添加到git分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17890693/