LoginSignup
31
35

More than 5 years have passed since last update.

.gitignoreを後から適用する手順

Last updated at Posted at 2017-07-25

はじめに

Git上で気軽にコードを書き始めてコミットをうっかり作ってしまった後で、.gitignoreの作り忘れに気づいたときに、管理対象を修正するための手順について。

手順

1 .gitignoreを作る。

SourceTreeの場合、ブラウザの右上の「設定」ボタン→右上の「高度な設定」→「リポジトリ限定無視リスト」の「編集」を押す。
 例えば、次のような条件にします。

.gitignore
# Xcode (from gitignore.io)
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xcuserstate
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa

# CocoaPod
Pods/*
Podfile.lock

# others
*.swp
UserInterfaceState.xcuserstate
!.gitkeep
.DS_Store

一度、ここでコミットしておきます。

2. 作業状態を解消する。

 スタッシュするなど。

3. カレントディレクトリをプロジェクトのフォルダに移動した後、キャッシュを削除する。

 ターミナル.appから、git rm -r --cached .

4. コミットする

 管理対象に.gitignoreが反映された状態のコミットが完成します。

31
35
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
31
35