6

f()
{
cd "$1"
git stash ; git stash drop
while git checkout HEAD^; do : ; done
for b in $(git branch | tail -n +2)
do git branch -D "$b"; git checkout -b "$b"; git push -f; done
for t in $(git tag); do git tag -f "$t"; done
git push --tags -f
}

for p in $(find "$HOME" -type d -name .git ) ; do f "$p"/.. & done

Comments
  • 3
    AKA why you should disable force push on master.
  • 1
    God is that code ugly.
  • 3
    @IntrusionCM try if it runs well
  • 0
    @electrineer nope. Such poopoo isn't worth being executed.
  • 1
    Have your git projects in /git
  • 0
    @IntrusionCM How should i do better? Consider i wanted to use bash because everyone knows it and bash is a ugly language. devrant has no way of formatting code and the text on devrant is very large, so i wanted to reduce the amount of code and lines.
  • 0
    @happygimp0

    Pastebin would certainly help or @highlight ^^

    Plus there are logical errors if I'm not mistaken...

    git checkout HEAD is run twice, one time should be sufficient.

    The detached head is necessary for the following part I guess.

    git branch --list instead of "git branch" would be a tad more readable and future proof, I think.

    tail -n +2 is kinda hacky, acts as a filter for the default branch I think? grep -v '*' might be a better fit, as an asterisk isn't an allowed branch name and the current branch is marked with an asterisk.

    git branch -D is a shortcut for --delete --force which deletes the branch regardless of it's status...

    git checkout -b should checkout the branch from remote...

    I cannot make sense of the force push?

    Retagging all tags is kinda disturbing XD
  • 0
  • 2
    @IntrusionCM you just proved that you didn't understand what the script does. Yet you still bashed it. Now you deserve to run it on your machine.
  • 1
    @IntrusionCM "git checkout HEAD is run twice, one time should be sufficient."

    Ok, you didn't understand what the script does. It is `git checkout HEAD^` The ^ is important. It checks out the previous commit. And it is not run twice, it is run till it fails which is the case when the HEAD reaches the first commit.

    What the script does: Search all git repositories (currently done in the $HOME directory but path can be changed in case you store your local git projects somewhere else). And then for every git project do the following:

    Set all branches and all tags to the first commit. push everything forcefully to the server. Without a backup or some other place which have the git repositories stored, all the project data except the ones included in the first commit are gone.
Add Comment