Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

git how to undo a pushed commit

git revert <commit_hash>
Comment

git undo pushed commit

git reset <previous label or sha1>
git commit -am "commit message"
git push -f <remote-name> <branch-name>  //  git push -f origin master
Comment

github undo last pushed commit

git reset <previous label or sha1>
git commit -am "blabla"
git push -f <remote-name> <branch-name>
Comment

how to revert last pushed commit

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
Comment

how to undo a commit that has not been pushed

Run the following command to revert the last commit.


$ git reset --soft HEAD~


Note: You can specify multiple commits by placing a number at the end.

For instance, if we want to undo the last two commits,
we can run the following command.


$ git reset --soft HEAD~2
Comment

how to revert last pushed commit

git reset <previous label or sha1>
git push -f <remote-name> <branch-name>  //  git push -f origin <branch-name>
Comment

how to undo last pushed commit

git revert <commit_hash>
Comment

how to undo a bunch of commit sent that was pushed

git revert <oldest_commit_hash>..<latest_commit_hash>
Comment

undo pushed commit

git reset <previous label or sha1>
Comment

how to undo a commit sent that was pushed and keep local changes

git reset <previous label or sha1>
Comment

how to undo an already pushed commit

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.
Comment

PREVIOUS NEXT
Code Example
Shell :: Apply .gitignore on an existing repository 
Shell :: windows edit file cmd 
Shell :: check vm ram details in linux 
Shell :: Input is required, but Expo CLI 
Shell :: wsl add directory to path 
Shell :: test if file is executable bash 
Shell :: linux speed up video 
Shell :: gitlab create branch 
Shell :: give all users access to root folder 
Shell :: git merge vs git merge --no-ff 
Shell :: bash rm all except 
Shell :: shebang line 
Shell :: echo variable bash 
Shell :: cmd rename multiple files 
Shell :: create strapi app 
Shell :: terminal delete all files that start with 
Shell :: npm install dev dependencies 
Shell :: export bigquery scheam 
Shell :: git push with gpg key 
Shell :: download file using scp hostfile 
Shell :: edge download ubuntu 
Shell :: install github cli 
Shell :: installing docker curl wget 
Shell :: install Homebrew on mac or linux 
Shell :: pynacl pip install 
Shell :: how to run docker not with sudo 
Shell :: ssh save password 
Shell :: centos set permissions on folder recursively 
Shell :: make git use a ssh key 
Shell :: convert cer to crt linux mint 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =