Can git commit “empty versions” of new, non-empty files?

前端 未结 2 1477
挽巷
挽巷 2021-02-04 03:43

Can git commit empty versions of some files? The case in point is that I need new (untracked), non-empty files to first be added and committed as empty files, so as to

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-04 04:34

    Automatically add all empty files and folders


    Force add all files

    $ git add -Af
    

    You can automatically add a .gitignore file in every empty folder.

    $ find $PATH_TO_REPOSITORY -type d ! -path "*.git*" -empty -exec cp .gitignore '{}'/ \;
    

    You can automatically add a .gitkeep file in every empty folder.

    $ find $PATH_TO_REPOSITORY -type d ! -path "*.git*" -empty -exec touch '{}'/.gitkeep \;
    

提交回复
热议问题