git 정리(2)

catchv·2022년 8월 24일
0

git

목록 보기
2/3

1. git 저장소 만들기

$ git init

2. git clone

$ git clone https://github.com/libgit2/libgit2 [디렉토리명]

3. git 상태

Untracked : git에 포함되지 않음
Unmodified : git에 commit 된 상태
Modified : git에 포함된 파일이 수정됨
Staged : git에 포함된 파일이 수정되고 스테이징으로 이동

4. 상태별 명령어

1) Add the file(Untracked -> Staged)

$ git add README

2) Edit the file(Unmodified -> Modified)

$ vi [파일명]

3) Stage the file(Modified -> Staged)

$ git add README

4) Commit(Staged -> Unmodified)

$ git commit -m "[comment]"

5) Remove the file(Unmodified - > Untracked)

$ git rm --cached README
$ git rm README ( 작업 디렉토리에서도 파일 삭제 )

4-1. 상태 되돌리기
1) commit 전 상태 변경
Staged, Modified -> Unmodified, Modified, Untracked의 이전 상태로 변경됨.
예) Untracked -> Staged -> git restore -> Unmodified
예) Modified -> Staged -> git restore -> Modified
예) Unmodified -> Modified -> git restore -> Unmodified

$ git restore [파일명]

3) commit 후 이전 commit으로 변경

# 나중에 다시 정리
$ git reset HEAD

5. 기타 명령어

1) 파일 이름 변경하기

$ git mv file_from file_to
# 위의 내용과 동일함.
$ mv README.md README
$ git rm README.md
$ git add README

2) commit 히스토리

$ git log
$ git log -p -2 	# 마지막 두개의 변경된 내용을 확인한다.
$ git log --stat 	# 변경 통계정보를 보여준다.
$ git log --pretty=[oneline, short, full, fuller] # 표시 형식 옵션
$ git log --pretty=format:"%h - %an, %ar : %s"
# ca82a6d - Scott Chacon, 6 years ago : changed the version number
$ git log --pretty=format:"%h %s" --graph
$ git log --since=2.weeks

6. remote 저장소 확인

$ git remote -v

7. remote 저장소 추가

$ git remote add pb https://github.com/paulboone/ticgit

8. remote branch 확인

$ git remote show [remote 저장소 ex)origin]

9. remote 저장소 이름 변경

$ git remote rename [old] [new]

0개의 댓글