search

Home  >  Q&A  >  body text

github - git how to filter files or directories

The git I built locally is then associated to the github repository, and the server pulls content from github.
Now I want to filter out the configuration files when submitting, because the configurations on the local and server are different
Then I wrote a .gitignore file with the configuration file directory in it. This method did not work. The local changes are pushed to github. When the server pulls from github, it still pulls the changes in the configuration file directory without filtering them out.

The second method is to directly add the configuration file directory to the local .gitinfoexclude but it still fails to be filtered. What's going on? The following are the rules written. .gitignore is added both on the server and locally. The second one is only added locally

PHP中文网PHP中文网2799 days ago890

reply all(3)I'll reply

  • 世界只因有你

    世界只因有你2017-05-02 09:52:48

    First of all, the poster needs to make it clear that the local file will be automatically read when it is added to the temporary storage area. .gitignore文件,根据其中的设置过滤相应的文件。所以楼主应该在添加到暂存区之前,就判断.gitignore文件是否生效,而不是推送到远程了才判断。
    你可以通过git status -s命令查看那些想过滤的文件是否被过滤掉,如果没有,那么很可能是因为那些文件之前已经在暂存区,.gitignoreFiles cannot filter those files that have been previously in the temporary storage area. In this case, you can use the following command:

    git rm --cached files-you-want-to-ignore

    At this time, you can use the git status -s command to check if it is indeed ignored, then you can perform subsequent add, commit, and push operations.

    reply
    0
  • 阿神

    阿神2017-05-02 09:52:48

    You have given a method to filter files.
    Maybe these files have been added to the warehouse. If you don’t want to track the files in the warehouse, follow the following command
    Ignore tracking

    $ git update-index --assume-unchanged /path/to/file       

    Resume tracking

    $ git update-index --no-assume-unchanged /path/to/file  

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-02 09:52:48

    is .gitignore 规则没生效 要先git rm -r --cached

    reply
    0
  • Cancelreply