git filter-branch chmod
Posted
by
Evan Purkhiser
on Stack Overflow
See other posts from Stack Overflow
or by Evan Purkhiser
Published on 2012-10-20T09:12:55Z
Indexed on
2012/10/20
11:01 UTC
Read the original article
Hit count: 288
I accidental had my umask set incorrectly for the past few months and somehow didn't notice.
One of my git repositories has many files marked as executable that should be just 644. This repo has one main master branch, and about 4 private feature branches (that I keep rebased on top of the master).
I've corrected the files in my master branch by running find -type f -exec chmod 644 {} \;
and committing the changes. I then rebased my feature branches onto master.
The problem is there are newly created files in the feature branches that are only in that branch, so they weren't corrected by my massive chmod commit. I didn't want to create a new commit for each feature branch that does the same thing as the commit I made on master. So I decided it would be best to go back through to each commit where a file was made and set the permissions.
This is what I tried:
git filter-branch -f --tree-filter 'chmod 644 `git show --diff-filter=ACR --pretty="format:" --name-only $GIT_COMMIT`; git add .' master..
It looked like this worked, but upon further inspection I noticed that the every commit after a commit containing a new file with the proper permissions of 644 would actually revert the change with something like:
diff --git a b
old mode 100644
new mode 100755
I can't for the life of me figure out why this is happening. I think I must be mis-understanding how git filter-branch
works.
My Solution
I've managed to fix my problem using this command:
git filter-branch -f --tree-filter 'FILES="$FILES "`git show --diff-filter=ACMR --pretty="format:" --name-only $GIT_COMMIT`; chmod 644 $FILES; true' development..
I keep adding onto the FILES
variable to ensure that in each commit any file created at some point has the proper mode.
However, I'm still not sure I really understand why git tracks the file mode for each commit. I had though that since I had fixed the mode of the file when it was first created that it would stay that mode unless one of my other commits explicit changed it to something else. That did not appear to the be the case.
The reason I thought that this would work is from my understanding of rebase
. If I go back to HEAD~5
and change a line of code, that change is propagated through, it doesn't just get changed back in HEAD~4
.
© Stack Overflow or respective owner