I have a git repo which has some invalid folder and source committed and deleted. I want to rewrite the history by git filter-repo
. Is it possible to keep the commit hash not changing when doing rewrite.
Asked
Active
Viewed 1,345 times
1

Gavin
- 95
- 9
-
Why do you want the hashes to be the same? – JoelFan Jul 28 '20 at 01:40
-
https://stackoverflow.com/questions/29106996/what-is-a-git-commit-id – phd Jul 28 '20 at 03:41
-
1@JoelFan For example in Phabricator (or any sofware management tool), tasks/specs are linked to commit hashes. Rewriting history is not likely to keep the links. – PJ127 Dec 17 '20 at 13:58
-
If that's the case you should create tags to make sure all those commits remain reachable, even after history is rewritten. You don't have to tag every commit... just the last commit in the branch that is going to be rewritten. (Of course, if it's easier to tag every commit, like in an automated process connected to the management tool, then no reason not to) – JoelFan Dec 17 '20 at 18:32
2 Answers
5
No, it's not possible. The hash is calculated using the content of the committed files. Since you are removing some of the content, the hash will be different.

JoelFan
- 37,465
- 35
- 132
- 205
0
No, this answer gives more detail but basically a commit hash is based the changes made. If the changes change then so will the commit hash.

Daly
- 787
- 2
- 12
- 23
-
2A commit hash is *not* based on changes made. It is based on the *contents* after that commit is made, as well as the hash of the previous commit. – JoelFan Jan 26 '21 at 04:51