Get git not to show untracked files

后端 未结 6 817
刺人心
刺人心 2020-12-23 20:16

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 (

6条回答
  •  悲哀的现实
    2020-12-23 21:08

    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:

    1. 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.

    2. 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.

提交回复
热议问题