Git · 코드 기록
Git 명령어 /버전 만들기, 태그 관리
짱코딩러
2022. 11. 14. 22:08
경로 확인
pwd
버전 만들기
1. 로컬 저장소 만들기
git init
$ git init
Initialized empty Git repository in F:/test/.git/
입력한 루트에 .git 파일이 생성됨
2. 작업 디렉터리 상태 확인하기
(미리 a.txt 파일을 생성해 주었음)
git status
$ git status
On branch master #현재 기본 브랜치(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)
3. 스테이지에 올리기
#하나 올리기
git add 파일명
#모든 파일 올리기
git add .
#입력해 주고
$ git add a.txt
#잘 됐는지 확인
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: a.txt
4. 커밋하기
git commit -m "커밋 메세지"
#또는
git commit --message "커밋 메세지"
$ git commit -m "first commit"
[master (root-commit) 4f5a437] first commit
1 file changed, 1 insertion(+)
create mode 100644 a.txt
#잘 됐는지 확인
$ git log #현재 브랜치의 커밋 목록 출력
commit 4f5a4375d28bbeb6fdeb9fdae00ceac15f5ec868 (HEAD -> master)
#HEAD(현재 브랜치의 최신 커밋)가 master 브랜치에 있다.
Author: Jieun <kkbg52@gamil.com>
Date: Mon Nov 14 22:17:21 2022 +0900
first commit
+스테이지 추가와 커밋 동시에 하기
: 깃이 변경 사항을 추적하는 파일만 가능 (한 번이라도 커밋한 적 있는 파일)
git commit -am "커밋 메시지"
+커밋 메세지 자세히 적기
#a.txt파일 추가
$ git add a.txt
#커밋
$ git commit
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
# Changes to be committed:
# modified: a.txt
#
~
~
~
F:/test/.git/COMMIT_EDITMSG [unix] (22:31 14/11/2022) 1,0-1 All
#a또는 i입력 (입력 모드로 전환)
-- INSERT --
#커밋 메세지 입력
third commit #제목
#한 줄 띄어줌
This is my third commit #내용
#esc 눌러주고 (명령 모드로 전환)
:write || :w
:quit || :q
#확인해보자 (현재 브랜치의 커밋 목록 출력)
$ git log
5. 커밋 조회하기
#짧은 커밋 해시와 커밋 메세지 제목만 출력
git log --oneline
#각각의 커밋이 무엇을 어떻게 변경했는지 출력
git log --p || $ git log --patch
#각 커밋을 그래프 형태로 출력 (소스트리 처럼)
git log --graph
#모든 브랜치의 커밋 목록 조회
git log --branches
태그 관리하기
1. 태그 추가하기
1) HEAD(현재 브랜치의 가장 최신 커밋)가 가리키는 커밋에 태그 붙이기
git tag 태그명
$ git tag v1.0.0
2) 특정 커밋에 태그 붙이기
git tag 태그 커밋
#커밋 해시 확인
$ git log --oneline
5c5d7b9 (HEAD -> master, tag: v1.0.0) third commit
35856e9 second commit
4f5a437 first commit
#(두번째)커밋에 태그 달기
$ git tag v0.0.1 35856e9
2. 태그 조회하기
git tag --list || git tag -l || git tag
3. 태그 삭제하기
git tag --delete 태그
$git tag --delete v0.0.1