HOWTO · Git
Git에 파일 추가
이 기사에서는 Git의 리포지토리에 파일을 추가하는 다양한 방법을 보여줍니다.
이 기사에서는 Git의 저장소에 파일을 추가하는 다양한 방법에 대해 설명합니다.
Git에서 git add 명령을 사용하여 모든 파일 추가
아래와 같이 git add 명령어로 예외 없이 모든 파일을 추가할 수 있습니다.
git add -A
-A 인수는 Git이 인덱스에 있는 모든 파일을 추가하도록 지시합니다. Git은 커밋을 위해 미추적, 수정 및 삭제된 파일을 준비합니다.
또는 현재 디렉토리에 파일을 준비하도록 Git에 지시하는 git add 명령을 실행할 수 있습니다.
예시:
pc@JOHN MINGW64 ~/Git/Delftscopetech (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
deleted: README.md
modified: Sample.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
Sample.txt.bak
Tutorial.txt
no changes added to commit (use "git add" and/or "git commit -a")
위의 예에는 다음 파일이 있는 인덱스가 있습니다.
- 수정된
Sample.tx파일. - 삭제된
README.md파일. - 그리고 두 개의 추적되지 않은 파일.
git add -A 명령을 실행하여 아래와 같이 커밋할 모든 파일을 준비합니다.
git add -A
Git이 파일을 준비했는지 확인하기 위해 git status 명령을 실행해 보겠습니다.
pc@JOHN MINGW64 ~/Git/Delftscopetech (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
deleted: README.md
modified: Sample.txt
new file: Sample.txt.bak
new file: Tutorial.txt
파일을 커밋할 준비가 되었습니다.
Git에서 확장자로 파일 추가
때때로 단계별 파일 형식이 필요할 수 있습니다. 예를 들어 .js 파일 또는 .txt 파일.
git add 명령을 사용하여 와일드카드와 파일 확장자를 입력합니다. 아래는 예시입니다.
디렉토리에 커밋을 위해 준비하려는 JavaScript 파일이 있습니다.
pc@JOHN MINGW64 ~/Git/Delftscopetech (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
deleted: README.md
modified: Sample.txt
new file: Sample.txt.bak
new file: Tutorial.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
New Text Document.txt
New.js
다음 컨텍스트에서 git add 명령을 실행할 수 있습니다.
$ git add *.js
Git이 파일을 준비했는지 확인하기 위해 git status 명령을 실행해 보겠습니다.
pc@JOHN MINGW64 ~/Git/Delftscopetech (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: New.js
deleted: README.md
modified: Sample.txt
new file: Sample.txt.bak
new file: Tutorial.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
New Text Document.txt
보시다시피 New.js 파일은 커밋을 위해 준비되었습니다.
삭제 및 수정된 파일은 Git에서만 추가
git add 명령을 -u 인수와 함께 사용하여 Git이 커밋을 위해 삭제 및 수정된 파일만 추가하도록 지시합니다.
예시:
pc@JOHN MINGW64 ~/Git/Delftscopetech (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: New.js
deleted: README.md
modified: Sample.txt
new file: Sample.txt.bak
new file: Tutorial.txt
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: Sample.txt
deleted: Sample.txt.bak
두 파일을 준비하려면 아래 명령을 실행합니다.
$ Git add -u
Git이 두 파일을 준비했는지 확인하기 위해 git status 명령을 실행합니다.
pc@JOHN MINGW64 ~/Git/Delftscopetech (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: New.js
deleted: README.md
modified: Sample.txt
new file: Tutorial.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
New Text Document.txt
커밋을 위해 삭제 및 수정된 파일을 추가했습니다.