2012-04-19 7 views
7

Soluzione: rimuovere --cached da git rm -r --cached submodule/name. Scripted per riferimento.git rm -r --cache non rimuove la cartella e il contenuto del sottomodulo


Sto cercando di rimuovere un modulo git basata su this SO answer, ma il modulo non viene rimosso.

Aggiungere il sottomodulo, confermare le modifiche, quindi cancellarlo utilizzando git rm -r --cached $path/to/submodule (meno il trailing /), confermare le modifiche, ma il sottomodulo è ancora lì.

Posso usare rm -rf submodules/lift_sbt_24 per eliminare la cartella e il contenuto, ma perché non lo fa git rm -r --cached?

(cancellando la sezione pertinente .gitmodules funziona bene, non è un problema, quindi non menzionati qui)

Questo è git 1.7.5.4 su Ubuntu 11.10, FWIW. Esempio completo:

$> git submodule add [email protected]:lift-stack/lift_24_sbt.git submodules/lift_24_sbt 
Adding submodule from repo [email protected]:lift-stack/lift_24_sbt.git as submodules/lift_24_sbt 
Cloning into submodules/lift_24_sbt... 
remote: Counting objects: 619, done. 
remote: Compressing objects: 100% (375/375), done. 
remote: Total 619 (delta 172), reused 593 (delta 147) 
Receiving objects: 100% (619/619), 1.74 MiB | 112 KiB/s, done. 
Resolving deltas: 100% (172/172), done. 
$> git status 
# On branch master 
# Your branch is ahead of 'origin/master' by 1 commits. 
# 
# Changes to be committed: 
# (use "git reset HEAD <file>..." to unstage) 
# 
# modified: .gitmodules 
# new file: submodules/lift_24_sbt 
# 
$> git add -a 
$> git commit 'added submodules/lift_24_sbt' 
[master 9894113] update 
2 files changed, 4 insertions(+), 0 deletions(-) 
create mode 160000 submodules/lift_24_sbt 
$> git rm -r --cached submodules/lift_24_sbt 
rm 'submodules/lift_24_sbt' 
$> git status 
# On branch master 
# Your branch is ahead of 'origin/master' by 1 commits. 
# 
# Changes to be committed: 
# (use "git reset HEAD <file>..." to unstage) 
# 
# deleted: submodules/lift_24_sbt 
# 
# Untracked files: 
# (use "git add <file>..." to include in what will be committed) 
# 
# submodules/lift_24_sbt/ 
$> git add -a 
$> git commit -m 'deleted submodules/lift_24_sbt' 
# On branch master 
# Your branch is ahead of 'origin/master' by 1 commits. 
# 
nothing to commit (working directory clean) 
$> ls -al submodules/lift_24_sbt/ 
total 1060 
drwxr-xr-x 5 kurtosis kurtosis 4096 2012-04-18 17:26 ./ 
drwxrwxr-x 6 kurtosis kurtosis 4096 2012-04-18 17:26 ../ 
drwxrwxr-x 8 kurtosis kurtosis 4096 2012-04-18 17:32 .git/ 
drwxrwxr-x 2 kurtosis kurtosis 4096 2012-04-18 17:26 project/ 
drwxrwxr-x 3 kurtosis kurtosis 4096 2012-04-18 17:26 src/ 
-rw-rw-r-- 1 kurtosis kurtosis  931 2012-04-18 17:26 build.sbt 
-rw-rw-r-- 1 kurtosis kurtosis  463 2012-04-18 17:26 .gitignore 
-rw-rw-r-- 1 kurtosis kurtosis  91 2012-04-18 17:26 README.md 
-rwxrwxr-x 1 kurtosis kurtosis  110 2012-04-18 17:26 sbt* 
-rw-rw-r-- 1 kurtosis kurtosis  131 2012-04-18 17:26 sbt.bat 
-rw-rw-r-- 1 kurtosis kurtosis 1041753 2012-04-18 17:26 sbt-launch.jar 
$> git --version 
git version 1.7.5.4 

risposta

12

Quello che stai vedendo è corretto; git rm --cached -r fa non, infatti, rimuovere i file dallo working tree, solo dallo index. Se si desidera git per rimuovere i file da indexe il working tree, non si deve utilizzare --cached. Vedere lo git-rm man page per ulteriori informazioni.


Di seguito è una spiegazione di ciò che hai fatto. Suppongo che tu abbia digitato i passaggi che hai fatto, invece di copiare da un terminale; per quanto ne so, git add -a è not a known git-add flag; Sono anche abbastanza sicuro che volevi dire anche git commit -m <message>.

I passi cut-down che hai preso:


# First, add the submodule. 
$> git submodule add [email protected]:lift-stack/lift_24_sbt.git submodules/lift_24_sbt 
# Check that the submodule exists. (It does). 
$> git status 
# Add everything to the staging area from the working tree. 
$> git add -a 
# Commit all changes. 
$> git commit 'added submodules/lift_24_sbt' 

A questo punto, hai aggiunto con successo il modulo, e tutto funziona come previsto.
Cosa si prova a fare successivo è quello di rimuovere il modulo:

$> git rm -r --cached submodules/lift_24_sbt 

Nota: qui, facciamo non rimuovere i file dal working index, solo dal index, a causa di il --cached:

--cached 
     Use this option to unstage and remove paths only from the index. Working tree 
     files, whether modified or not, will be left alone. 

Poi, controllare che abbiamo rimosso il modulo:

$> git status 
... <snip> 
# Changes to be committed: 
# (use "git reset HEAD <file>..." to unstage) 
# 
# deleted: submodules/lift_24_sbt 

Come si può vedere, il modulo è stato eliminato, e tutto è buono. Notare, tuttavia, che i file esistono ancora nell'albero di lavoro - è ancora possibile visualizzarli con ls.:)

+0

Grazie e sì intendevo 'git add -A' e' git commit -m'. Rimosso --cached da 'git rm -r $ 1' e [scriptato da esso] (https://github.com/byrongibson/scripts/blob/master/git-rm-submodule.sh). Forse non è saggio farlo in uno script, ma è almeno utile come riferimento passo-passo. – Kurtosis

1

Si può cercare di simpliyfy lo script, utilizzando un nuovo comando (git1.8.3 aprile 22d, 2013), dettagliato in una nuova risposta alla domanda "How do I remove a Git submodule?":

git submodule deinit 

Si dovrebbe rimuovere l'albero di lavoro del sottomodulo e annullare la registrazione da .git/config.