-1

I'm sorry for another git post but I've searched a lot and tried everything I saw before this post.

I changed to master from a "dirty" branch without noticing and all the commits merged to master and more.

I want to create a revert commit from a certain commit hash in the past.

For example, my head is 100 commits ahead from commit 'abcdef'. I want from my current head to create a revert which will make my new head same as it was after commit 'abcdef'.

Eventually all needs to be pushed to remote repository (bitbucket)

I used git-reset but it just brings me to the desired point in time, without the revert-commit. Is there a way to force a push of all files. I tried using 'git add -f filename' but when I do git status it is not there as there are no changes from the current head which is 'abcdef'

Tried: How to revert multiple git commits?

Resetting remote to a certain commit

Gal Ziv
  • 6,890
  • 10
  • 32
  • 43
  • Do you really want to revert? This will create additional commits that "undo" the incorrect ones. Or do you just want to reset branch `abcdef` back to its original state which will completely remove all of the commits. – Code-Apprentice Aug 05 '18 at 17:19
  • What do you mean by "dirty branch"? Did you have local changes which were not yet commited? Did you commit these changes directly to master? It will help if you provide the exact commands you performed that got you to the current state. – Code-Apprentice Aug 05 '18 at 17:22
  • @Code-Apprentice yes, i want to create one additional commit which revert all other 100 – Gal Ziv Aug 05 '18 at 21:00
  • 1
    @GalZiv if you really want "one single commit" to revert all, you need to use `git revert --no-commit`, otherwise git will make one revert commit for each commit until that you pass as argument – Johnny Willer Aug 05 '18 at 23:00
  • @JohnnyWiller yup this is what I used. thanks! – Gal Ziv Aug 07 '18 at 11:29

1 Answers1

1

Probably what you want is git reset --hard <commit>. This will reset the current branch to some other commit. If you have already pushed the branch to bitbucket, you will need to do git push -f to force push.

Beware

This will cause problems for other team members who are working on the same branch. Only do this if you are the only person working on the branch.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268