vishpat
vishpat

Reputation: 133

git push overwrote my changes

Me and one of my colleagues are working on a git master branch which has commit history as follows

A -> B -> C -> D -> E -> F -> HEAD

Now my colleague checked out the master branch at commit # "C" and started working making and committing local changes. In the meanwhile, I moved the master branch forward with commits "D" and "E".

Later on my colleague pushed his changes via commit "F" without doing a pull and this commit basically nuked my changes in commits "D" and "E". Is this expected ? why didn't git complain that his workspace is lagging that he should sync it to the HEAD before pushing his changes ?

Upvotes: 0

Views: 153

Answers (1)

John Szakmeister
John Szakmeister

Reputation: 46992

It sound like your colleague force pushed the branch, which will discard the commits you made if they weren't in his local branch. Git does generally complain when you attempt to push and your branch doesn't contain all the commits on the remote end. The only time I've seen Git update silently is when the repository is set up as a mirror.

I don't like removing the ability to force push because there are instances where it's the right thing to do. If you do want to disable them, you can do that by setting receive.denyNonFastForwards in the server-side repository. You may want to set receive.denyDeletes too, otherwise someone can delete the master ref, and then install a new one.

You could use a pre-receive hook to verify that master is not being rewound. update-paranoid from Git's contrib area is capable of doing this, along with some other nifty features.

Upvotes: 2

Related Questions