# check the branch that you committed to by accident, in this case, is master
git checkout master
# reset the branch back one commit
git reset --soft HEAD^
# use stash to record the current state of the working directory
git stash
# checkout the branch it should be in, in this case, is mymain
git checkout mymain
# apply the stash
git stash apply
# commit the changes
git commit -am "main commit"
# then push the changes to our main branch
git push origin mymain
# checkout the original branch, in this case, is master
git checkout master
# the last step is to force push the commit deletion to the original branch.
git push --force origin master
Hope this help's !!
tutorials, tips, tricks, commands, programming, linux, windows, database, sql, python, programming language, Fedora, drawing, painting, tutorial, tutorials
Friday, February 26, 2021
Fedora 33 : Bash script for GitHub to fix bad commit branch.
One mistake is to have changed in the [master] branch instead of [mymain].
This can be fixed with this bash script:
Posted by
Cătălin George Feștilă
Labels:
2021,
Fedora,
Fedora 33,
GitHub,
linux,
linux tools,
tutorial,
tutorials
Subscribe to:
Posts (Atom)