git – Why shouldn't I rewrite published commits?

Question:

I always read and say that it is dangerous to rewrite commits published in git (that is, they may exist in third-party repositories).

What problems does it cause, punctually? Why do these problems occur?

Answer:

It is not recommended to do git commit --amend or git reset in public repositories for the simple reason that new commits replace old ones and in the history of your repository it will look as if a piece of it has simply disappeared.

However, these tools exist for a reason and that reason is that they are useful for polishing or improving the history of our repositories. For example, if you had a repository with a lot of useless or obsolete commits then you have the opportunity to match them with the commits that are significant and in the end the history of your repository will look neat and clean.

You can see more information about times when it is useful to rewrite the history of repositories here .

The cautionary note is so that other developers who may have cloned your repository have no trouble navigating the commit history. If that happens and several simultaneous amends are made, it could cause quite a lot of confusion in the repository, although the probability is very low.

You can see this in a little more detail here .

Scroll to Top