Repo specific ignore files in git

前端 未结 4 2024

Is it possible to have repo specific .gitignore files? Eg:

[origin] .gitignore:

  • foo1.*
  • foo2.*

[another] .gitignore:

    <
相关标签:
4条回答
  • 2020-12-18 11:07

    You could probably do this using git hooks (the scripts in .git). post-checkout sounds good.

    0 讨论(0)
  • 2020-12-18 11:10

    Yes you can, just can't have them in the same folder. If you create a new folder, day "deploy" and publish your deploy data there, it will use the .gitignore in that folder (not the root one).

    0 讨论(0)
  • 2020-12-18 11:11

    Yes, you can put per repository ignore patterns in .git/info/exclude in each repository.

    (Note, this only affects what is ignored in each repository, it won't affect files that you actively place under source control and the push. I'm not completely clear on your desired use case.)

    0 讨论(0)
  • 2020-12-18 11:24

    My Situation:

    Having a file named alex.todo which contains my personal notes about the project. I have two remote repo to push(origin and alex). One for sharing the code with other developers(I use .gitignore to exclude the alex.todo file), one just for backing up this project which is ok to preserve the alex.todo file.

    My final solution:

    Using a temp branch to push the alex.todo to the backup repo.

    # Step 1
    git checkout -b alex # 'alex' or whatever branch name you prefer
    
    # Step 2
    # now you can edit your .gitignore to include your 'alex.todo' file
    
    # Step 3
    git add . && git commit -m 'commit some ignore files'
    git push alex alex:master # git push <remote> <local branch name>:<remote branch to push into>
    
    # Step 4
    git checkout master  # return to branch master and do any editings(commits)
    
    # Step 5
    # make sure branch alex is in sync with master whenever you want to push the project to the backup repo
    git checkout alex
    git merge master # .gitignore will not automatically be included for commit unless specifically added
    # now you can repeat step 3 to push the project to the backup repo
    
    0 讨论(0)
提交回复
热议问题