如何将新文件夹添加到git的分支中,而不让该文件夹出现在主分支中?
e.g.
git branch myNewBranch
git checkout myNewBranch
mkdir foo
git checkout master
ls
myNewBranch目录也被添加到主分支中
e.g.
git branch myNewBranch
git checkout myNewBranch
mkdir foo
git checkout master
ls
myNewBranch目录也被添加到主分支中
仅仅创建了文件夹并不意味着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.
编辑:为了澄清,您示例中的文件夹并没有被添加到主分支,实际上它也没有被添加到任何分支。