Gitで空のInitial commitを作る

#7b9ce088461e49eca55d4ddf22a1d9a0
2025.12.21
2025.12.21
  • まだフォルダ構成とかは決まってないけど、とりあえずリポジトリを初期化したい場合がある

  • git commitはデフォルトでは変更がない場合はコミットを作らせてくれない:

    % git init
    Initialized empty Git repository in .../.git/
    % git commit
    On branch main
    
    Initial commit
    
    nothing to commit (create/copy files and use "git add" to track)
  • --allow-emptyオプションを使うと、この挙動を回避して空のInitial commitを作ることができる:

    % git commit -m "Initial commit" --allow-empty
    [main (root-commit) f03a945] Initial commit
  • --allow-emptyはInitial commitを作る時に限らずいつでも、空コミットを作るために使うことができる