git - 如何在不将新文件夹添加到master的情况下将新文件夹添加到git分支

标签 git git-branch

如何在 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/

相关文章:

git - arc diff 禁用测试计划 'differential.require-test-plan-field' 不起作用

git - 一个 git 日志历史图表,每次提交一行,彩色,带日期

git - 如何 git svn 只获取具有特定模式的分支/标签?

git - git push 上的 "src refspec does not match"和 "failed to push some refs"错误

git - 如何从现有的远程分支创建本地分支?

Git 跟踪上游

git - 如何使用绝对路径和符号链接(symbolic link)解决 git add 中的问题

git - 如何卸载 git-for-windows 并在新位置重新安装?

linux - Git、单一游戏和跨平台开发

jenkins - 在提示符或 Android gradle 中检索 git 分支名称 : on Jenkins it returns HEAD