Edit a git commit already clicked

I accidentally overwritten the changes of another developer when merging in git. I know how to undo the last commit , i.e. merge.

My problem is that I have already pushed these commits into our online repository. Therefore, if I roll back, merge the merge again (with its modifications this time) and try to click it again, there will be a conflict (right?). How to deal with this?

EDIT To clarify, this is what the situation looks like:

commit A --- commit B --- merge 

But in the merge, I accidentally dropped the modifications made to commit A. This is not a problem. I know how to make changes locally (undo a merge). But my problem is that all this has been ported to our shared repository (think github or bitbucket).

+6
source share
1 answer

By default, remote servers will prohibit overwriting already committed commits. This is due to the fact that these new commits are different objects that are incompatible with previously published ones. This means that anyone who has already set off from the remote will have serious problems fixing it after overwriting the commit. Therefore, you should really review rewriting a commit with something else. Note that git revert also works with merge commits, so you might think about that.

However, you can still click on this overwritten commit, even if it conflicts with what is on the server. You can do this by pressing git push --force or git push -f .

+4
source

Source: https://habr.com/ru/post/969761/


All Articles