xxxxxxxxxx
git reset <previous label or sha1>
git push -f <remote-name> <branch-name> // git push -f origin <branch-name>
xxxxxxxxxx
git reset <previous label or sha1>
git commit -am "commit message"
git push -f <remote-name> <branch-name> // git push -f origin master
xxxxxxxxxx
To reset a brancj to some good commit:
β
In the server, move the cursor back to the last known good commit:
β
git push -f origin <last_known_good_commit>:<branch_name>
β
Locally, do the same:
β
git reset --hard <last_known_good_commit>
# ^^^^^^
# optional
xxxxxxxxxx
git reset <previous label or sha1>
git commit -am "blabla"
git push -f <remote-name> <branch-name>
xxxxxxxxxx
#Reset author for the current repo:
β
git config --local user.name "Alex Smith"
β
git config --local user.email alex@email.com
β
#Now reset the author of your commit without edit required:
β
git commit --amend --reset-author --no-edit
β
#Force push your changes without overwriting anyone else's commits:
β
git push --force-with-lease
β
β
xxxxxxxxxx
Note: the steps below does not remove the previous commit.
It simply reverts it to what it was.
β
Step one is to ensure that you are on a clean working directory.
You shouldn't have any open new changes.
β
Then you'll need to find the hash for the specific commit you are trying to undo.
You can find them on your online Repo (like GitHub, for instance).
β
Take this hash and then head back over to your terminal.
You can now revert this commit by executing the following command.
β
for example if the hash is f193a70
β
β
$ git revert f193a70 --no-edit
β
β
Note: The --no-edit is optional. It won't prompt you to edit
the commit message that way
β
Once executed, you'll note that it will do the opposite of the commit locally.
β
The command will return the files to what they used to be before.
β
Now all that's left is to push the reverted code.
β
β
$ git push
β
β
When you view your changes, you'll see the old commit is still there,
but a new revert commit replaces the changes.