push&pull
서로 다른 지역 저장소가 원격저장소를 중심으로 서로 소스 코드를 주고받는 방식
git push
를 통해 원격 저장소로 보낸다.
git pull
작업을 시작하기전에 pull을 하여 원격 저장소로 부터 최신 작업 상태를 불러와서 병합한다.
*push를 하기 전에 pull을 하지 않을 경우.
$ git push
To https://github.com/jinzza456/githome-office.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/jinzza456/githome-office.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
충돌이 일어나고 밑에 힌트를 준다.
이 경우 git pull 을 이용하여 원격 저장소의 내용을 불러와서 지역 저장소에서 충돌이 일어나는 부분을 해결한 다음 push를 해야한다.
git pull을 하면 원격 저장소와 병합이 되면서 새로운 커밋이 만들어진다.
그 후 git push 를 하면 원격 저장소로 문제없이 올라간다.
pull과 fetch의 차이점
$ git log --decorate --all --oneline
3eaac9f (HEAD -> master, origin/master) edit spelling
b9d55f0 Merge branch 'master' of https://github.com/jinzza456/githome-office
31ce75b 3rd homemade
ecd30b2 1st officemade
2b1299a 2nd homemade
f72cf1d 1st homemade
git log --decorate --all --oneline를 하였을 때
지역 저장소(master) 와 원격 저장소(origin) 가 같은 커밋을 가르키는걸 알 수 있다.
$ git log --decorate --all --oneline
8906837 (origin/master) fetch test
3eaac9f (HEAD -> master) edit spelling
b9d55f0 Merge branch 'master' of https://github.com/jinzza456/githome-office
31ce75b 3rd homemade
ecd30b2 1st officemade
2b1299a 2nd homemade
f72cf1d 1st homemade
git log --decorate --all --oneline를 하였을 때
지역 저장소(master)와 원격 저장소(origin)가 서로 다른 커밋을 가르킨다.
즉 원격 저장소(origin)가 지역 저장소(master)를 앞서고 있다는걸 알 수 있다.
*원격 저장소의 최신 커밋을 다운 받아 그 주소를 기억해 놓았지만 아직 지역 저장소의 마스터 브렌치에는 어떠한 변화도 주지 않은 상태이다.
원격저장소로 부터 가져온다음 병합을 시키지 않기 때문에
원격저장소에 있는 내용과 지역 저장소에 있는 내용의 차이점을 비교해 볼 수 있다.
$ git diff HEAD origin/master
diff --git a/home.txt b/home.txt
index 94a0524..6c4da0c 100644
--- a/home.txt
+++ b/home.txt
@@ -1,2 +1,3 @@
this is made at home
this is added at office
+this is text for git fetch
git diff 를 통해 HEAD(지역 저장소의 현재위치)와 origin/master(원격 저장소의 마스터브렌치)의 차이점을 확인 할 수 있다.
+this is text for git fetch
'+'는 추가된 내용
문제가 없음을 확인 하였을 경우
git merge origin/master
위의 코드를 통해 원격 저장소의 파일과 병합시켜 준다.
이후 git log를 통해 확인해 보면
$ git log --decorate --all --oneline
8906837 (HEAD -> master, origin/master) fetch test
3eaac9f edit spelling
b9d55f0 Merge branch 'master' of https://github.com/jinzza456/githome-office
31ce75b 3rd homemade
ecd30b2 1st officemade
2b1299a 2nd homemade
f72cf1d 1st homemade
지역 저장소와 원격 저장소가 같은 커밋을 가리키는걸 확인 할수있다.
git tag
우리가 알고있는 v2.1.0 과 같은 버전을 입력하는 것 외에 태그명을 입력할 수 있는 명령어이다.
릴리즈를 할 때 마다 최신 커밋 아이디는 항상 바뀌지만 tag는 항상 같은걸 가르킨다.
tag명은 중복 할 수 없지만 하나의 커밋 아이디에 복수의 tag를 가질 수 있다.
아래의 명령으로 특정 커밋 아이디에 tag를 생성한다.
git tag 1.0.0 태그할 커밋 아이디
git tag를 통해 목록을 볼수 있다.
vim을 통해 파일을 수정한 뒤
git log를 해보면
commit 288c0fc12b93612d4fa0f9d4d981852ec0b9f604 (HEAD -> master)
Author: jinzza456 <jinzza456@gmail.com>
Date: Thu Oct 7 14:16:59 2021 +0900
no tag
commit 450181716544770950ca2c338a106bfa593b8d37 (tag: 1.0.0)
Author: jinzza456 <jinzza456@gmail.com>
Date: Thu Oct 7 14:07:19 2021 +0900
edit tag test
commit 70869fb26d789980e2eba43df09288550a5e282b
Author: jinzza456 <jinzza456@gmail.com>
Date: Thu Oct 7 14:05:09 2021 +0900
tag test
현재 브렌치가 가리키는 커밋은 바뀌었지만 tag는 지정한 커밋 아이디만을 가리키고 있는 것을 알 수 있다.
*tag로 지정해 놓은 특정 커밋으로 이동하고 싶은경우
git checkout 1.0.0
위의 명령을 통해 특정 tag로 이동할 수 있다.
git log를 해보면
jinzz@DESKTOP-I8KEDHO MINGW64 /c/githome ((1.0.0))
$ git log
commit 450181716544770950ca2c338a106bfa593b8d37 (HEAD, tag: 1.0.0)
Author: jinzza456 <jinzza456@gmail.com>
Date: Thu Oct 7 14:07:19 2021 +0900
edit tag test
commit 70869fb26d789980e2eba43df09288550a5e282b
Author: jinzza456 <jinzza456@gmail.com>
Date: Thu Oct 7 14:05:09 2021 +0900
tag test
1.0.0 태그의 커밋으로 돌아간 것을 확인할 수 있다.
*다시 master로 돌아가고 싶을 경우
git checkout master
git tag -d tag명
annotated tag vs light weigth tag
annotated tag는 더 무거운 tag로 앞서 만들었던 tag보다 더 많은 정보를 가지고 있다.
git tag -a 1.1.0 -m "태그에 대한 설명"
tag명과 그에대한 설명을 추가한다.
1.0.0 --> light weigth tag
1.1.0 --> annotated tag
git tag -v를 통해 이 두가지를 비교해 보았을때
1.0.0 --> light weigth tag
$ git tag -v 1.0.0
error: 1.0.0: cannot verify a non-tag object of type commit.
아무런 정보도 나오지 않는 반면
1.1.0 --> annotated tag
$ git tag -v 1.1.0
object 288c0fc12b93612d4fa0f9d4d981852ec0b9f604
type commit
tag 1.1.0
tagger jinzza456 <jinzza456@gmail.com> 1633584996 +0900
anotated tag
error: no signature found
태그를 만든 사람과 태그에 대한 설명이 추가가 된 것을 알 있다.
*tag를 원격 저장소로 보내는 법
git push 만으로는 원격 저장소로 태그까지 보낼 수 없다.
$ git push --tags
Enumerating objects: 1, done.
Counting objects: 100% (1/1), done.
Writing objects: 100% (1/1), 156 bytes | 156.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/jinzza456/githome-office.git
* [new tag] 1.0.0 -> 1.0.0
* [new tag] 1.1.0 -> 1.1.0
git push --tags 를 통해 tag가 원격 저장소로 올라간 것을 알 수 있다.
github에서 커밋파일 위를 보면 tags로 들어가면 태그가 추가 된것을 확인 할 수 있다.
Tags의 오른쪽 draft a new release 를 통해 부가적인 정보를 추가 할 수 있다.
아랫 부분의 Publish release 를 하게 되면 공식 적으로 릴리즈 되어서 사용자들이 사용할 수 있게끔 된다.