1

I created a branch for my change and did a lots of commit over there. But then I wanted to rollback my latest commit. sO i did following 1. I checkout the previous commit with git checkout on my branch. 2. Then I did my changes to local directory and committed the changes.

Now I am not able to push it to the branch head. It is showing as detached head and can't see this commit in GIT UI.

Please note I want to push the changes to the head of my branch and not to the master. Any help ?

2 Answers2

0
# create a branch where you're currently pointing at
git branch temp

git checkout your_branch
git merge temp

and the commit you made out of your branch will be brought in, it should be a fast-forward (so without an unnecessary merge commit).

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
  • Thanks for the response. But I already have checkout my branch. And then I checkout the previous commit and then I made changes and committed it back. I just need to push it. – Abhishek Shah Oct 03 '19 at 11:54
0

If I understood correctly, you checked out your previous commit without resetting your branch to it, therefore detaching HEAD. To bring back the branch to your current HEAD (and drop the commit it was pointing to), just use:

git checkout -B your_branch # Reset your_branch to HEAD and attach to it

If you had already pushed the dropped commit, you will need to --force the next push.

Quentin
  • 62,093
  • 7
  • 131
  • 191