| by Arround The Web | No comments

How to Undo a Particular Commit in Git that’s Been Pushed to Remote Repos

Git is one of the most common and versatile tracking tools which is easy to use. Developers can use it in their troubles when they commit undesirable modifications to a local repository. Sometimes, they want to undo the entire commit with all added changes instead of going through them manually. It might be possible these changes have been pushed to the centralized repository. For this purpose, a simple user can reset the HEAD pointer by utilizing the “git reset” command.

This post will discuss how to undo a particular commit in Git, which is pushed to the remote repository.

How to Undo a Desired Commit in Git that’s Been Pushed to GitHub server?

Try the below-stated instructions to undo the particular commit in Git, which is pushed to the remote repository:

  • Switch to the desired local repository.
  • List repository content that needs to push to the remote server.
  • Check the remote URL list.
  • Push data to the GitHub server.
  • Display the log history.
  • Type out the “git reset HEAD~” command.
  • Verify by viewing the Git commit history.

Step 1: Navigate to Git Desired Repository

Type out the “cd” command and navigate to the particular local repository:

$ cd "C:\Users\nazma\Git\perk6"

Step 2: List Repositories’ Content

Now, display the list of existing content by running the “ls” command:

$ ls

Step 3: Show Remote URL

Next, execute the provided command to show the available remote URL:

$ git remote -v

Step 4: Push Local Changes to Remote

Then, push all the modified data into the remote repository by executing the “git push” command:

$ git push -u origin feature

Here, the “origin” is the remote URL name, and “-u” represents the upstream branch. As you can see, all local data is pushed to the GitHub server:

Step 5: View Log History

To check the log history of the current working branch, run the “git log” command:

$ git log --oneline -5

According to the below-given output, the HEAD is pointing to the “6f3c…” commit SHA-hash:

Step 6: Reset HEAD Position

After that, use the following command to reset the HEAD position and revert the applied changes on the Git repository:

$ git reset HEAD~

Step 7: View Log History

Now, view the log history of the current working local branch by utilizing the “git log” command:

$ git log --oneline -5

As you can see, the HEAD position is changed to the previous commit, the currently pushed commit is removed from the history and changes are undo:

That’s all! You have learned how to undo the particular commit in Git, which is pushed to the remote repository.

Conclusion

To undo the particular commit in Git, which is pushed to the remote repository, first, move to the desired local repository and list its content to be pushed to the remote server. Then, check the remote URL list and push data to the GitHub server. After that, view the log history and run the “git reset HEAD~” command. Lastly, verify it by viewing the Git reference log history. This post described the procedure of undoing a particular commit in Git, which is pushed to the remote repository.

Share Button

Source: linuxhint.com

Leave a Reply