如何切换分支时摆脱子模块.我不明白为什么git clean说它删除了子模块但没有.这是一个错误吗?下面是剪切和粘贴步骤来重现.
git --version
git version 1.7.8.4
git init submod
cd submod
echo "This is a submodule" > README.txt
git add .
git commit -m "Initial commit"
cd ..
git init prog
cd prog
echo "This is a program" > README.txt
git add .
git commit -a -m "Initial commit"
git checkout -b topic1
git submodule add ../submod
git commit -m "Added submodule"
git checkout master
#warning: unable to rmdir submod: Directory not empty
#Switched to branch 'master'
git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# submod/
#nothing added to commit but untracked files present (use "git add" to track)
git clean -fd
#Removing submod/
git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# submod/
#nothing added to commit but untracked files present (use "git add" to track)
Run Code Online (Sandbox Code Playgroud)
sim*_*ont 43
这不是一个错误,它是记录在案的行为.来自man git-clean:
如果未跟踪的目录由不同的git存储库管理,则默认情况下不会删除它.
该submod目录是一个不同的git存储库; 如果你想删除它,Use -f option twice if you really want to remove such a directory.
git clean -f -f -d submod 确实删除submod.请参阅下面的步骤(几乎相同;不同的git version和硬编码的submodule路径,因为否则会git吐出假人).
$ git --version
git version 1.7.5.4 # Note, different git-version.
Run Code Online (Sandbox Code Playgroud)
git init submod
cd submod
echo "This is a submodule" > README.txt
git add .
git commit -m "Initial commit"
cd ..
git init prog
cd prog
echo "This is a program" > README.txt
git add .
git commit -a -m "Initial commit"
Run Code Online (Sandbox Code Playgroud)
submod作为git submodule在topic1分支.
git checkout -b topic1
git submodule add /Users/simont/sandbox/SOTESTING/Subdir-testing/submod
git commit -m "Added submodule"
Run Code Online (Sandbox Code Playgroud)
$ git checkout master
warning: unable to rmdir submod: Directory not empty
Switched to branch 'master'
git status
# On branch master
# Untracked files:
# (use "git add ..." to include in what will be committed)
#
# submod/
#nothing added to commit but untracked files present (use "git add" to track)
Run Code Online (Sandbox Code Playgroud)
git-clean,那么实际 git-clean.
git clean -fd
#Removing submod/
git status
# On branch master
# Untracked files:
# (use "git add ..." to include in what will be committed)
#
# submod/
#nothing added to commit but untracked files present (use "git add" to track)
$ # As we can see, we haven't actually removed anything yet.
$ ls
README.txt submod
$ git clean -f -f -d submod
Removing submod/
$ ls
README.txt
$ git status
# On branch master
nothing to commit (working directory clean)
Run Code Online (Sandbox Code Playgroud)
jor*_*v92 11
要在签出不同的分支后删除“剩余”子模块,您可以运行以下命令。此命令将递归清理主存储库和所有子模块。 警告:这也将删除所有未跟踪的文件。
git clean -xffd && git submodule foreach --recursive git clean -xffd
Run Code Online (Sandbox Code Playgroud)
要查看哪些文件将被删除而不实际删除,请添加 -n 标志。
git clean -nxffd && git submodule foreach --recursive git clean -nxffd
Run Code Online (Sandbox Code Playgroud)
该命令的关键是传递给 Git clean 的 double-f。否则,Git 将不会删除属于子模块的文件夹(即包含 .git 子文件夹的文件夹)。
| 归档时间: |
|
| 查看次数: |
13700 次 |
| 最近记录: |