Source Code Management(SCM) : 코드 관리 도구(버전을 통해 관리)
Version Control System(VCS) : 버전 컨트롤 시스템
local computer 상의 파일 버전 관리
git hub
등 필요폴더
기준으로 프로젝트(코드) 관리
git init
git bash
에서 프로젝트 시작 폴더로 이동 후 아래의 명령어로 git
관리 시작(master)
라고 붙음$ git init
.git
폴더 생성 == git으로 폴더가 관리되어 있음.git
폴더 삭제 == git으로 폴더를 관리하지 않겠다.(master)
붙음git status
$ git status
$ git status
On branch master # 마스터 브랜치에 있음
No commits yet # 아직 commit 없음
nothing to commit (create/copy files and use "git add" to track) # commit 할 게 없음
$ git status
On branch master
No commits yet
Untracked files: # 추적하고 있지 않음
(use "git add <file>..." to include in what will be committed)
a.txt # 추가된 파일
nothing added to commit but untracked files present (use "git add" to track)
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: a.txt
$ git status
On branch master
Changes not staged for commit: // commit하기 위해 변화들이 stage에 추가되지 않았다.
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: a.txt // 수정 발생한 파일
no changes added to commit (use "git add" and/or "git commit -a")
git add [파일명]
버전을 만들/commit할/스냅샷을 찍을
파일 선택$ git add [파일 이름] # .은 모든 변경 사항을 staging area로 올림
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: a.txt
git commit -m ["커밋 메시지"]
commit
하여, 버전 관리 진행git commit -m
: git commit 시, message와 함께 커밋$ git commit -m "커밋 메시지"
$ git status
On branch master
nothing to commit, working tree clean # working tree(현재 폴더)가 클린, commit해야할 것도 없다
$ git config --global user.email ["이메일주소"]
$ git config --global user.name ["사용자명"]
git log
$ git log
git log
: 버전 관리 이력 상세 조회$ git log
commit 59b2d89081c56d05eb157c92f789b9d2c09b6313 (HEAD -> master)
Author: HJ Ryu <*@gmail.com>
Date: Tue Sep 15 15:21:31 2020 +0900
Add World to a.txt
commit fcc302724d603e16003333bbd4bb5bbeab7e9ff8
Author: HJ Ryu <*@gmail.com>
Date: Tue Sep 15 15:15:07 2020 +0900
Modify a.txt
commit d4393df37937a0cb78008169e32906a5f4b2b093
Author: HJ Ryu <*@gmail.com>
Date: Tue Sep 15 14:50:59 2020 +0900
First Commit
git log --oneline
: 버전 관리 이력 한줄 조회$ git log --oneline
59b2d89 (HEAD -> master) Add World to a.txt
fcc3027 Modify a.txt
d4393df First Commit
git checkout [버전명]
$ git checkout [버전명]
git checkout [d4393df]
: d4393df 버전으로 돌아감$ git checkout d4393df
Note: switching to 'd4393df'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at d4393df First Commit
*@*** MINGW64 ~/basic_git ((d4393df...)) # d4393df 버전으로 돌아감
git checkout master
: 최신 버전으로 돌아감*@*** MINGW64 ~/basic_git ((d4393df...))
$ git checkout master
Previous HEAD position was d4393df First Commit
Switched to branch 'master'
*@*** MINGW64 ~/basic_git (master) # 최신 버전(master)으로 돌아감
git remote add [저장소의 이름][저장소의 URL]
git init
이 된 상태origin
origin
$ git remote add origin https://github.com/Journey-R/TIL.git
git remote -v
$ git remote
origin
$ git remote -v
origin https://github.com/Journey-R/TIL.git (fetch)
origin https://github.com/Journey-R/TIL.git (push)
git push[저장소명][브랜치명]
$ git push origin master
add
|rm
-> commit
-> push
$ git add README.md
$ git commit -m "add README.md"
$ git push origin master
git remote remove [저장소명]
git add -u
: git add
없어진 파일이나 이름이 바뀐 파일을 인식하지 못하기 때문에, 수정(update)된 파일들을 추가하고 싶을 경우 사용한다.git add .
: 현재 폴더 내부의 모든 변화를 state에 추가한다.git rm
$ git rm [파일명]
$ git rm --cached [파일명]
처음
으로 프로젝트 복제할 때 : git clone [원격 저장소의 주소]
$ git clone https://github.com/Journey-R/TIL.git
# 완료 메시지
Cloning into 'TIL'...
remote: Enumerating objects: 30, done.
remote: Counting objects: 100% (30/30), done.
remote: Compressing objects: 100% (24/24), done.
remote: Total 30 (delta 11), reused 23 (delta 4), pack-reused 0
Unpacking objects: 100% (30/30), 10.62 KiB | 159.00 KiB/s, done.
git pull [저장소명] [브랜치명]
$ git pull origin master
# 완료 메시지
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 3 (delta 1), reused 3 (delta 1), pack-reused 0
Unpacking objects: 100% (3/3), 247 bytes | 35.00 KiB/s, done.
From https://github.com/Journey-R/TIL
* branch master -> FETCH_HEAD
d3ea488..d6c89f4 master -> origin/master
Updating d3ea488..d6c89f4
Fast-forward
django.md | 0
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 django.md
git diff [파일명]
$ git diff READM.md
# 변경 사항 있을 경우 출력됨
diff --git a/README.md b/README.md
index c06601f..3452f05 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
# 백일장
-다음 제시어로 n행시를 완성하세요.
+다음 제시어로 n행시를 완성하세요~!
## 제시어
- 사: 사차산업은
$ code . # 현재 폴더의 파일 VS Code에서 열기
$ code .. # 상위 폴더의 파일 VS Code에서 열기