0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Git] 動作を試す 実行例14:.gitignoreでバージョン管理から外す

Posted at

Gitの動作を理解するために、Gitのコマンドを実際に試して、結果を見てみました。

1つの記事内で一連のGitコマンドが完結しているので、これら一連のコマンドを順に実行させて結果を見ることで、一連のGitの動作を実際に体感でき、一通り独習することが可能です。

※前回記事のリポジトリ状態からの続きになっています。

前回記事へ 目次へ:Git関連記事のまとめページ 次回記事へ

実行例

.gitignoreファイルやGitコマンドでバージョン管理から外す方法
https://engineer-lifestyle-blog.com/code/gitignore-file-and-command-to-exclude/

.gitignoreの配置: 
├.git/
└.gitignore

.gitignoreの内容例: 
│# comment
│abc.log
│bin/
│# comment
│/abc.log
│/bin/
│# comment
│.vs/
│*.pyc
│/**/*.o
└# comment

-----

(※ひとまず適当にファイルを作成)
echo Test-Ignore1 > test1.test-ignore
mkdir test-ignore
echo Test-Ignore2 > test-ignore/test2.test-ignore

dir /b
↓
結果: 
test-ignore
test1.test-ignore
test1.txt
test2.txt
test4.txt

git status
↓
結果: 
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        test-ignore/
        test1.test-ignore

-----

※.gitignoreでバージョン管理から外す
echo *.test-ignore > .gitignore

git status
↓
結果: 
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .gitignore

-----

echo /*.test-ignore > .gitignore

git status
↓
結果: 
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .gitignore
        test-ignore/

echo / *.test-ignore > .gitignore

git status
↓
結果: 
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .gitignore
        test-ignore/
        test1.test-ignore

-----

echo *-ignore/ > .gitignore

git status
↓
結果: 
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .gitignore
        test1.test-ignore

-----

(※始めの状態に戻す)
del .gitignore
git clean -f -df

git status
↓
結果: 
On branch master
nothing to commit, working tree clean

環境

Windows 10、PortableGit-2.40.0-64-bitを使用、全てローカルPC上で実施、GitHub等は不使用。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?