When doing git commit
, is there a way to not display the untracked files in my editor (defined in $EDITOR
)? I know how to do so in the shell (
Add the file names - or templates (wild cards) for the file names - to the .gitignore file and add that to the repository:
git add .gitignore
git commit -m 'Added .gitignore file'
For example, for my Go repository, I have a .gitignore file containing:
*.o
*.a
*.so
*.pl
*.6
*.out
_obj/
_cgo_defun.c
_cgo_export.c
_cgo_export.h
_cgo_gotypes.go
*.cgo1.go
*.cgo2.c
example/example
ifix1/esqlc-cmds.c
I should probably compress the '_cgo_
' names with a wild card; the other '.c' file is generated from a '.ec' file so it does not need to be tracked.
You can temporary use the git commit option -uno
to mask untracked files (git help commit
).
If you want a permanent solution use the .gitignore
file.
For instance, if you want to ignore the file bar.foo
and any file with the .bak
extension, you juste have to create a .gitignore
file in the root directory of your project containing :
bar.foo
*.bak
Some file are ignored by a global gitignore
file (for instance, dot file and directory are ignored).
There are times notifications aren't wanted about either a changed repo file or a new file that needs to be added to the repo. However, adding the name of the file to .gitignore
might not be a good option, either. For example, locally-generated files that other users aren't likely to generate (e.g., files created by an editor) or files of experimental test code might not be appropriate to appear in a .gitignore
file.
In those cases, use one of these solutions:
If the file is a changed repo file
Use the command:
git update-index --assume-unchanged "$FILE"
To undo this, use the command:
git update-index --no-assume-unchanged "$FILE"
The update-index
command doesn't work with new files that haven't been added to the repo yet, though.
If the file is new and not added to the repo
Add its filename to the repo's exclude
file:
echo "$FILE" >> .git/info/exclude
This also works for changed repo files, but there isn't a specific undo command for it. The exclude
file would need to be edited and the filename deleted from it. Or other commands could approximate it:
ex -s -c"g/^${FILE}\$/d" -cwq .git/info/exclude
Note that this overwrites the existing exclude
file and if the filename specified contains special characters that could affect the regular expression, the results are unpredictable.
This usage of the exclude
file is recommended by the page "Ignoring files" on GitHub Help.
From the git-commit man page:
-u[], --untracked-files[=] Show untracked files (Default: all). The mode parameter is optional, and is used to specify the handling of untracked files. The possible options are: · no - Show no untracked files · normal - Shows untracked files and directories · all - Also shows individual files in untracked directories. See git-config(1) for configuration variable used to change the default for when the option is not specified.
If you don't ever want to commit them to your repo, use a .gitignore
file to ignore them. More details can be found on the gitignore man page. They won't show up as untracked files when entering your commit message in your $EDITOR
.
If you simply don't want to see them when committing, set the Git config variable status.showUntrackedFiles
to no
, as noted here:
$ git config --global status.showUntrackedFiles no
If you are using git-extensions tool in the commit tab just select the files you want to ignore, right click and add them to .gitignore