.gitignore 작동원리

정은경·2020년 7월 12일
0

다음의 상황은 어떻게 될까요?

어떤 폴더의 일부는 git에 포함되어야하고, 일부는 포함되지 말아야할 때!

(venv) (base) marie@MarieJucBookPro:~/PycharmProjects/play-with-django(master⚡) » mkdir ignore_test
(venv) (base) marie@MarieJucBookPro:~/PycharmProjects/play-with-django(master⚡) » cd ignore_test 
(venv) (base) marie@MarieJucBookPro:~/PycharmProjects/play-with-django/ignore_test(master⚡) » ls -al > should_include.txt
(venv) (base) marie@MarieJucBookPro:~/PycharmProjects/play-with-django/ignore_test(master⚡) » ls -al > should_NOT_include.txt
(venv) (base) marie@MarieJucBookPro:~/PycharmProjects/play-with-django/ignore_test(master⚡) » ls -al
total 16
drwxr-xr-x   4 marie  staff  128 Jul 12 10:53 .
drwxr-xr-x  11 marie  staff  352 Jul 12 10:53 ..
-rw-r--r--   1 marie  staff  239 Jul 12 10:53 should_NOT_include.txt
-rw-r--r--   1 marie  staff  170 Jul 12 10:53 should_include.txt
(venv) (base) marie@MarieJucBookPro:~/PycharmProjects/play-with-django/ignore_test(master⚡) » cd ..
(venv) (base) marie@MarieJucBookPro:~/PycharmProjects/play-with-django(master⚡) » 
(venv) (base) marie@MarieJucBookPro:~/PycharmProjects/play-with-django(master⚡) » git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .gitignore
        .idea/
        django_player/
        ignore_test/
        manage.py

nothing added to commit but untracked files present (use "git add" to track)
(venv) (base) marie@MarieJucBookPro:~/PycharmProjects/play-with-django(master⚡) » 

.gitignore 파일 작성하기

(venv) (base) marie@MarieJucBookPro:~/PycharmProjects/play-with-django(master⚡) » cat .gitignore|grep should
*/should_NOT_include.txt
# When using Gradle or Maven with auto-import, you should exclude module files,
(venv) (base) marie@MarieJucBookPro:~/PycharmProjects/play-with-django(master⚡) » 
(venv) (base) marie@MarieJucBookPro:~/PycharmProjects/play-with-django(master⚡) » git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .gitignore
        .idea/
        django_player/
        ignore_test/
        manage.py

nothing added to commit but untracked files present (use "git add" to track)
(venv) (base) marie@MarieJucBookPro:~/PycharmProjects/play-with-django(master⚡) » git add ignore_test/
(venv) (base) marie@MarieJucBookPro:~/PycharmProjects/play-with-django(master⚡) » git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   ignore_test/should_include.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .gitignore
        .idea/
        django_player/
        manage.py

(venv) (base) marie@MarieJucBookPro:~/PycharmProjects/play-with-django(master⚡) » 
(venv) (base) marie@MarieJucBookPro:~/PycharmProjects/play-with-django(master⚡) » git commit -m "gitignore test"                                    129 ↵
[master c1d5920] gitignore test
 1 file changed, 4 insertions(+)
 create mode 100644 ignore_test/should_include.txt
(venv) (base) marie@MarieJucBookPro:~/PycharmProjects/play-with-django(master⚡) » git push origin master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 424 bytes | 424.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To https://github.com/EunkyoungJung/play-django.git
   4b2a07b..c1d5920  master -> master
(venv) (base) marie@MarieJucBookPro:~/PycharmProjects/play-with-django(master⚡) » 
(venv) (base) marie@MarieJucBookPro:~/PycharmProjects/play-with-django(master⚡) » 
(venv) (base) marie@MarieJucBookPro:~/PycharmProjects/play-with-django(master⚡) » 
(venv) (base) marie@MarieJucBookPro:~/PycharmProjects/play-with-django(master⚡) » 

ignore에 포함된 파일을 제외하고 pushe됨을 확인

.gitignores for django

profile
#의식의흐름 #순간순간 #생각의스냅샷

0개의 댓글