github - Undo git reset --hard and git push -f by using this strategy? -
can undo git reset --hard && git push -f origin master having else hasn't pulled in these changes run "git push -f origin master" change original "git push -f origin master" executed first?
i assume using 'star' topology, 1 central repository , each developer pushes/fetches to/from one.
it depends on when person merged common branch.
a safer way first have git push -f origin origin/master:master, , (except you) git push origin origin/master:master (without -f).
the first push discard commit, , leave branch @ state person last fetched. , pushes think latest master. easier checking beforehand had latest source.
why git push -f origin origin/master:master , not git push -f origin master? latter pushes local branch. theformer pushes believe correct remote version. if git fetch on regular basis, never git merge local master, first version correctly handle this.
actually there's better way of handling this. (as it's default) can use git reflog browse history of branch. every commit you've created, including no longer 'visible' because amended, rebased, whatever. can dig through commit hash before accidental git reset --hard, git reset --hard $hash , git push -f origin master yourself.
better yet, always, always triple-check before pushing -f. or consider banning altogether.
Comments
Post a Comment