Git ignore .git folder

后端 未结 5 1554
梦如初夏
梦如初夏 2021-02-04 09:41

I have a php project that uses composer for package management. One of the packages is another project belonging to the same repo. I have a need to commit my entire vendor folde

5条回答
  •  伪装坚强ぢ
    2021-02-04 10:24

    You can use git hooks to achieve what you want. Thinking out of the box, you could use pre-commit hook to rename the .git directory of your included project, eg. to ".git2", add all files in the latter project except the ".git2" directory, commit all, push it and finally use post-commit hook to rename ".git2" folder back to ".git" in your module.

    1) Create pre-commit file under .git/hooks/ of your root repo with contents:

    #!/bin/sh
    mv "vendor/modulename/.git" "vendor/modulename/.git2"
    
    git rm --cached vendor/modulename
    git add vendor/modulename/*
    git reset vendor/modulename/.git2
    

    2) Create post-commit file under .git/hooks/ also with contents:

    #!/bin/sh
    mv "vendor/modulename/.git2" "vendor/modulename/.git"
    

    3) Change a file in your repo and finally:

    git commit -a -m "Commit msg"
    git push
    

提交回复
热议问题