Question

I have a previous commit (9770912) to which I want temporarily return and make a push to server to see if the bug appeared on site after this commit. Also I want to get back to the current state of code after this. When executed git checkout 9770912, I couldnt make any push or commit.

Was it helpful?

Solution

When executed git checkout 9770912, I couldnt make any push or commit.

That is because you are in a detached HEAD mode, meaning that you are not in a branch (so, you cannot push that "non-branch")

You could make another branch on that commit, and force push it to your remote master branch

git checkout -b aNewBranch
git push -f origin aNewBranch:master

Then you can revert to what master was:

git push -f origin master:master

OTHER TIPS

@vonc is right about the detached HEAD

you should go back to your HEAD

git reset HEAD --hard

and here you have also 2 choices :

Make it clean with a revert of your commit and push again :

git revert 9770912
git push origin master (I suppose you are on your master)

Or you can rebase your branch and make it disappear (more complex and you will rewrite the history)

git rebase -i HEAD~5 (-i for interactive mode and we will check the five latest commits from the HEAD)

When you are in this mode you should simple delete the line with your commit (with vim for example you can use dd keyboard letter (twice))

Save and quit (:wq)

git push origin master --force (you have to force to rewrite your history and make it disappear)

Be careful with this method as if you have coworkers it will generate conflict with their last history as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top