Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@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.
-
@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 -
@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.
-
@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.
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
rant