HomeLinuxHow one can Undo a Specific Commit in Git that’s Been Pushed...

How one can Undo a Specific Commit in Git that’s Been Pushed to Distant Repos


Git is among the most typical and versatile monitoring instruments which is simple to make use of. Builders can use it of their troubles once they commit undesirable modifications to an area repository. Generally, they need to undo your complete commit with all added adjustments as a substitute of going by them manually. It is likely to be doable these adjustments have been pushed to the centralized repository. For this objective, a easy consumer can reset the HEAD pointer by using the “git reset” command.

This submit will talk about how you can undo a specific commit in Git, which is pushed to the distant repository.

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

Strive the below-stated directions to undo the actual commit in Git, which is pushed to the distant repository:

  • Change to the specified native repository.
  • Record repository content material that should push to the distant server.
  • Test the distant URL record.
  • Push knowledge to the GitHub server.
  • Show the log historical past.
  • Kind out the “git reset HEAD~” command.
  • Confirm by viewing the Git commit historical past.

Step 1: Navigate to Git Desired Repository

Kind out the “cd” command and navigate to the actual native repository:

$ cd “C:CustomersnazmaGitperk6″

Step 2: Record Repositories’ Content material

Now, show the record of current content material by operating the “ls” command:

Step 3: Present Distant URL

Subsequent, execute the supplied command to indicate the accessible distant URL:

Step 4: Push Native Modifications to Distant

Then, push all of the modified knowledge into the distant repository by executing the “git push” command:

$ git push -u origin characteristic

Right here, the “origin” is the distant URL title, and “-u” represents the upstream department. As you possibly can see, all native knowledge is pushed to the GitHub server:

Step 5: View Log Historical past

To examine the log historical past of the present working department, run the “git log” command:

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

Step 6: Reset HEAD Place

After that, use the next command to reset the HEAD place and revert the utilized adjustments on the Git repository:

Step 7: View Log Historical past

Now, view the log historical past of the present working native department by using the “git log” command:

As you possibly can see, the HEAD place is modified to the earlier commit, the presently pushed commit is faraway from the historical past and adjustments are undo:

That’s all! You’ve gotten realized how you can undo the actual commit in Git, which is pushed to the distant repository.

Conclusion

To undo the actual commit in Git, which is pushed to the distant repository, first, transfer to the specified native repository and record its content material to be pushed to the distant server. Then, examine the distant URL record and push knowledge to the GitHub server. After that, view the log historical past and run the “git reset HEAD~” command. Lastly, confirm it by viewing the Git reference log historical past. This submit described the process of undoing a specific commit in Git, which is pushed to the distant repository.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments