Reputation: 35
I was working on my old Android phone's kernel. I imported the manufacturer's changes and splitted them into commits. However, after I finished the process, I realized that there are a lot of files that are shown as edited, but is the only the permission that's edited. On the git logs, as a result, it shows things like these:
diff --git a/include/linux/usb/audio.h b/include/linux/usb/audio.h
old mode 100644
new mode 100755
I searched the internet, and found out that I can solve this by doing
git config core.filemode false
However, this seems to change only for future commits.
How can I edit all my previous commits (almost as 70+ commits) and remove these files as recorded as being edited?
Thanks.
Upvotes: 2
Views: 3472
Reputation: 490068
You can't. Old (existing) commits are set in stone.
In general you should never have to change core.filemode
as Git should have set it correctly. On any Windows system it would therefore already be set to false
for you. It looks like you, or at least someone, somehow managed to get a setup that was wrong, that produced these incorrect commits.
You cannot fix the incorrect commits, but if they bother you enough, you can make new, very-slightly-different commits. These new, very-slightly-different commits should exactly match the old commits in all respects but one: the recorded file modes in the new commits will match the recorded file modes in their parent commits, so that there is no difference at all in the revised snapshots when each revised snapshot is compared to its parent snapshot.1
The downside to doing this work, as will be obvious from footnote 1, is that you have to revise many commits, and now you have a new and different repository with replacements for those 70+ old commits. You must now get everyone who has a clone of this Git repository to switch to another new clone, in which the 70+ new (fixed) commits replace the 70 old (slightly incorrect) commits.
It's usually simpler—as well as quite harmless—just to live with the existing mistake.
1Remember that each Git commit contains a full snapshot of every file, including the file's mode. The issue you have is that at some point, someone told Git—perhaps through this somehow-incorrect core.filemode
setting—that all the new commits should record the files as mode 100755
(rwxr-xr-x
) instead of mode 100644
(rw-r--r--
). The first commit that went from 100644 to 100755 produces the diff. From then on, each new commit that says 100755
produces no diff, because the mode doesn't change.
As soon as you make one corrected commit in which the updated files are all mode 100644
, though, that corrected commit compares nicely to its parent, but poorly to the subsequent uncorrected commit. So you must now make another new commit, the same as the subsequent commit but with the modes corrected. This repeats for every new commit.
The end result is that you must double up all 70+ commits: now you have 140+ commits. Then you simply stop using the "wrong" ones, and use the "right" ones instead.
Upvotes: 1