如何在 git 的分支中添加一个新文件夹而不让该文件夹出现在 master 分支中?
e.g.
git branch myNewBranch
git checkout myNewBranch
mkdir foo
git checkout master
ls
myNewBranch 目录也添加到 master
如何在 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,它实际上没有添加到任何分支。
看起来你有两个让你困惑的误解。
add
和commit
一个文件(例如在您签出不同的分支时修改或删除它)。.gitignore
在该目录中添加一个空目录并提交。