marinehilt.blogg.se

Git undo commit remote repository
Git undo commit remote repository











This means that 5bc1d11 was force pushed over by 83da01d, which means 5bc1d11 is the one we need to restore. Let's take the final example: jamietanna force-pushed the chore/spotless branch from 5bc1d11 to 83da01d 2 days ago When force pushing on GitHub, the UI shows information about the force-pushes that have occurred: This tells us that the last push to the remote was 5e2791da4 and it overrode c574fceb1, so c574fceb1 is the one we need to restore to. $ git reflog refs/remotes/origin/update/wiremock-docs If we're using the branch update/wiremock-docs, on the Git remote origin, then we can use git reflog like so: If you don't have that output any more, we can fortunately use git reflog to recover this. This means that the left-hand side commit hash, c574fceb1 is the one we need to restore to.

git undo commit remote repository

Git is telling us that it's just force pushed the branch update/wiremock-docs to commit 5e2791da4, when before it was c574fceb1. + c574fceb1.5e2791da4 update/wiremock-docs -> update/wiremock-docs (forced update) Total 5 (delta 4), reused 0 (delta 0), pack-reused 0 Let's say that the output they see is: Enumerating objects: 9, done. The first thing is to make sure that they didn't close the window, or lose the output of the command they'd just run to force push. From the Git CLI With the output from git push -force

#GIT UNDO COMMIT REMOTE REPOSITORY HOW TO#

Unfortunately, without a practical example, I can't share too much about how to do that. Note that these are from the viewpoint of your local machine being the one who's pushed it - if trying to recover someone else's, you may need to git fetch -all at some point, and play around with the commands. In the spirit of blogumentation, I thought I'd document it for future me. One of my colleagues recently got in touch with me to say that they'd force pushed to the wrong branch, and needed a hand to recover things if possible.įortunately, this is something I've had to do numerous times - because I've got it wrong myself - so I was able to help. I really like telling a descriptive story with our Git commit history, and spend a fair bit of time making sure that the history provides the right level of information.īecause writing Git commit messages, and having a good commit history, leads to needing to rewrite Git history, I'm quite comfortable with git rebase and rewriting Git history safely.











Git undo commit remote repository