How can I add an empty directory to a Git repository?

后端 未结 30 2500
离开以前
离开以前 2020-11-21 04:52

How can I add an empty directory (that contains no files) to a Git repository?

30条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-21 05:25

    There's no way to get Git to track directories, so the only solution is to add a placeholder file within the directory that you want Git to track.

    The file can be named and contain anything you want, but most people use an empty file named .gitkeep (although some people prefer the VCS-agnostic .keep).

    The prefixed . marks it as a hidden file.

    Another idea would be to add a README file explaining what the directory will be used for.

提交回复
热议问题