0

i have seen similar topics here, but i didn't find the clear answer.

i have commited and pushed few changes on a remote branch, but that was a mistake and would like to reset this branch to the state it was couple of days ago. (using source tree btw)

- bad pushed commit
- bad pushed commit
- bad pushed commit
- place i want to return to
- older commits

if i do a hard reset to the place i want to return to and then force push it. Will that do the trick, are there any issues with that ?

tkruse
  • 10,222
  • 7
  • 53
  • 80
Adrian
  • 347
  • 1
  • 6
  • 18
  • no issues but all other developers will have to do http://stackoverflow.com/a/9813888/1233686, and you should be careful if they have uncommitted changes. – hurturk Mar 31 '17 at 06:02
  • friend of mine, told me i can lose all of the history for this branch is it true ? – Adrian Mar 31 '17 at 06:20
  • I don't think so, you would just lose the bad commits like they never happened. Just copy your entire project directory before doing this, you can always recover by force pushing the backup one. – hurturk Mar 31 '17 at 06:22

3 Answers3

0

you can try this

git reset HEAD~

or reset to specific commit

git reset --hard <commit-hash>
git push -f origin master

or more information for git

please follow this link :- https://git-scm.com/docs/git-reset

Gohel Dhaval
  • 820
  • 1
  • 8
  • 12
0

Actually, the best way avoid merge conflicts (when other people is working on the same repo) is to git revert <SHA> those commits. It will not travel back in time and rewrite history but will create an "inverse" version of said commits.

git revert will create a new commit that's the opposite (or inverse) of the given SHA. If the old commit is "matter", the new commit is "anti-matter"—anything removed in the old commit will be added in the new commit and anything added in the old commit will be removed in the new commit.

Find more info here

0

This will fix it, but you have to be wary about changes made on top of these bad commits by other collaborators.

git reset HEAD~3 --hard
git push -f origin <branch-name>
Jack Gore
  • 3,874
  • 1
  • 23
  • 32