Question

I noticed a moment ago that my .gitconfig -file was public at my repo. It contains my secret tokens.

I git-add -u the file and committed. I am not sure whether this command removes the file from the previous commits too.

I want to be sure and search the file in my previous commits such that there is no such a file in my history.

How can you search the file in previous commits?


I run

git filter-branch --tree-filter 'rm .gitconfig' master     # Thanks to Greg!

I get

Rewrite 84dabfa2ea195ce9aad0309216858b302150017c (1/25)rm: .gitconfig: No such file or directory
tree filter failed: rm .gitconfig

The error message suggests me that I do not have the file at my commit history.

Is there any way to search the file in my commit history such that I do not need to run the removal to see that I do not have the file in my commit history?

Was it helpful?

Solution

Short answer:

git filter-branch --tree-filter 'rm -f .gitconfig' master   

Note the -f.

Long answer:

rm would return a non-zero return code when file does not exist. filter-branch think this is an error and stop the rewrite. Adding -f avoid this.

Note:

There is an alternative command:

git filter-branch --index-filter 'git rm --cached --ignore-unmatch .gitconfig' master

which is MUCH faster. This command is documented in the EXAMPLE section of the man page.

OTHER TIPS

To remove a file from all past Git history, you will need to rewrite all past commits using something like git filter-branch. However, doing this makes your new tree unmergeable with all past trees, so do this with care.

Reset all ewvisions in repository to global defaults (.gitconfig).

git filter-branch -f --commit-filter 'GIT_COMMITTER_NAME="`git config --get user.name`";GIT_AUTHOR_NAME="`git config --get user.name`";GIT_COMMITTER_EMAIL="git config --get user.email";GIT_AUTHOR_EMAIL="`git config --get user.email`";git commit-tree "$@";' HEAD
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top