-
-
Save nicktoumpelis/11214362 to your computer and use it in GitHub Desktop.
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 |
@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
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
git config --global alias.rinse '!git submodule foreach --recursive git clean -xfd && git submodule sync --recursive && git restore . --recurse-submodules'
git reset --hard --recurse-submodule
use this (see above)
git config --global alias.rinse '!git reset --hard --recurse-submodule && git submodule sync --recursive && git submodule update --init --force --recursive && git clean -ffdx && git submodule foreach --recursive git clean -ffdx'
git restore
@sambacha can you elaborate on why you added git restore
? What's the use-case?
```shell git restore@sambacha can you elaborate on why you added git restore? What's the use-case?
It resets the submodules back
git restore . --recurse-submodules
It resets the submodules back
Does it also take care of the git reset --hard --recurse-submodules
to discard any changes in the working trees? If so, why do the git restore
last and not first?
The key for me was git submodule sync
. Thank you @larsbrinkhoff @yuzhichang!
It's a sneaky issue whenever the URLs specified in .gitmodules
get updated, but the old URLs continue to silently be used (as shown by git submodule foreach --recursive git remote get-url origin
). Git should honestly warn us whenever the two are different.
Maybe
git submodule sync
?
For anyone coming new to all these commands, I believe this suggestion is 'as well', not 'instead' (see later comments for what this adds).
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