1

I reset a git branch by doing the following:

 git reset --hard someid

then I cherry picked some commits onto it, and pushed it to the remote like this:

git push --force origin develop

This was all fine, but now a collegue did a git pull, made a commit, did a push and now the stuff I removed with the reset is back.

What should I or we have done differently after the reset?

Maarten
  • 4,643
  • 7
  • 37
  • 51
  • 6
    You should've communicated with your team. Rewriting history always have the potential of bringing back the history you wanted removed because others already have it locally. If they're not told to handle this by recloning or removing the same changesets at their end, they might push back these changesets on their next push with no indication of wrongdoing. Force-pushing needs to be handled with care, not something that individual developers should do in isolation. – Lasse V. Karlsen Mar 13 '17 at 09:30
  • right.. so we communicated, but we didn't know it worked like this. I supposed that is an answer of some kind. Removing the local version of the branch and checking it out again is then the best way? – Maarten Mar 13 '17 at 09:36
  • It's better not to mess with public history in the first place. Only publish commits if you do not want to change them any more. If you have to change things, create a new commit, if you have to revert something, use `git revert ` to create a new commit reverting the old one. – kowsky Mar 13 '17 at 09:49
  • in general yes I know this, but we inadvertently had quite a few commits on that branch so we took this route. – Maarten Mar 13 '17 at 09:50

1 Answers1

3

Your colleague could have used git pull --rebase, and in each step instead of committing use git rebase --continue

Mithilesh Gupta
  • 2,800
  • 1
  • 17
  • 17
  • Be aware, though, that rebasing *can* re-introduce deliberately-discarded commits. As of Git 2.0 and later, it *can* be told to discard them, using `--fork-point`. It defaults to discarding them in the `git pull --rebase` and other simple rebase cases, and not discarding them in more complex manual rebase cases. See http://stackoverflow.com/q/42536989/1256452 for details. – torek Mar 13 '17 at 10:27