git clean -xfd | |
git submodule foreach --recursive git clean -xfd | |
git reset --hard | |
git submodule foreach --recursive git reset --hard | |
git submodule update --init --recursive |
this is nice. thanks!
Now this is a handy, awesome set of commands!
Not especially destructive, just does a little house-keeping post-commit.
Excellent, thank you.
Maybe git submodule sync
?
If you do have a script that checks out a git repo or you have removed submodules this script fails. I also would reorder the cleanup to the end in case of submodule changes. That's what I have now:
#! /bin/sh
git reset --hard
git submodule foreach --recursive 'git checkout -- . || :'
git submodule update --init --recursive
git clean -d -f -f -x
git submodule foreach --recursive git clean -d -f -f -x
I today faced the issue that I had staged files in submodules. To get this solved the full script is:
#! /bin/sh
git reset --hard
git submodule foreach --recursive 'git reset HEAD . || :'
git submodule foreach --recursive 'git checkout -- . || :'
git submodule update --init --recursive
git clean -d -f -f -x
git submodule foreach --recursive git clean -d -f -f -x
@Davidius86 In git reset HEAD . || :
I think the || :
is meant to be "or true"?
I'm curious why you use this instead of git reset --hard
?
I've written/found this a long time ago. I think it's time for an update.
Thanks a lot for sharing it!
Nice work!
Thanks for sharing!
Thanks for sharing!
Finally, something that works. Thx!
Git 2.14+ supports reset of the repo and submodules in one line: git reset --hard --recurse-submodule
Thank you everybody for your comments!
Git 2.14+ supports reset of the repo and submodules in one line:
git reset --hard --recurse-submodule
Awesome information!! Quite simple solution.
I revised the script:
#!/bin/bash
#Cleans and resets a git repo and its submodules
#https://gist.github.com/nicktoumpelis/11214362
git reset --hard
git submodule sync --recursive
git submodule update --init --force --recursive
git clean -ffdx
git submodule foreach --recursive git clean -ffdx
Use force twice to clean directorise with .git subdirectories:
git clean -xfdf
. I had some tangling submodules that would not get deleted with justgit clean -xfd
.