In my work tree I have a mixture of files in .gitignore:
If I want to rebuild my project from scratch, I can do git clean -x
to remove the build outputs in (1). But this also removes the sensitive files in (2).
Is there a way to mark a file so it's not affected by git clean
while still being ignored by git commit
?
If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a .gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.
git clean -X will remove any files matching the patterns in . gitignore . The -n at the end causes it to not actually remove files, only to dry run, reporting files that would have been removed. Add -d to also remove ignored directories.
You can create a .gitignore file in your repository's root directory to tell Git which files and directories to ignore when you make a commit. To share the ignore rules with other users who clone the repository, commit the .gitignore file in to your repository.
Let's say you have already added/committed some files to your Git repository and you then add them to your . gitignore file; these files will still be present in your repository index.
The documentation for git-clean
says that -x
:
-x
Don’t use the standard ignore rules read from .gitignore (per directory) and $GIT_DIR/info/exclude, but do still use the ignore rules given with -e options.
So if you want to keep, say, keys.pem
, you would call
git clean -fdxe keys.pem
You can also create alias for the command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With