Make git ignore files

前端 未结 2 1024
旧时难觅i
旧时难觅i 2021-02-01 19:32

I\'m trying to make git ignore some of my files and I found one description about how you could do this

From: http://github.com/guides/git-cheat-sheet T

相关标签:
2条回答
  • 2021-02-01 20:15

    https://www.gitignore.io/

    I created a web utility that can help you generate useful .gitignore files for your project. It will help you ignore operating system, programming language, and IDE generated files.

    0 讨论(0)
  • 2021-02-01 20:16

    According to man gitignore:

    DESCRIPTION

    A gitignore file specifies intentionally untracked files that git should ignore. Note that all the gitignore files really concern only files that are not already tracked by git; in order to ignore uncommitted changes in already tracked files, please refer to the git update-index --assume-unchanged documentation.

    So it doesn't help if you've already added them. It's mostly for preventing the addition in the first place. That way, you can ignore .tmp files and add a whole directory without worrying that you'll add the .tmp files.

    I believe you can remove them from the index with:

    git rm --cached file_to_stop_tracking_but_dont_want_to_delete.txt
    

    Update:

    Also, the .gitignore needs to be at the base directory or at least above where those directories are. Also, take the "*" out of the directories:

    phpMyAdmin/
    nbproject/
    inc/mysql_config.php
    !.gitignore
    

    And be careful of phpMyAdmin/ vs /phpMyAdmin vs phpMyAdmin. Also from man gitignore:

    • If the pattern ends with a slash, it is removed for the purpose of the following description, but it would only find a match with a directory. In other words, foo/ will match a directory foo and paths underneath it, but will not match a regular file or a symbolic link foo (this is consistent with the way how pathspec works in general in git).

    • If the pattern does not contain a slash /, git treats it as a shell glob pattern and checks for a match against the pathname without leading directories.

    • Otherwise, git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the pattern will not match a / in the pathname. For example, Documentation/*.html matches Documentation/git.html but not Documentation/ppc/ppc.html. A leading slash matches the beginning of the pathname; for example, /*.c matches cat-file.c but not mozilla-sha1/sha1.c.

    0 讨论(0)
提交回复
热议问题