git tag

  • commit에 이름을 달아주는 행위
  • 버전관리를 용이하게 해준다.

  • 위의 github의 release버전에 v1.21.3 이라는 tag가 작성되어있음을 확인 할 수 있다.

 

tag를 통한 브랜치 checkout

  • commit 2번에 firstTag, 1.0.0 이라는 tag를 지정
    • checkout {tag}를 통해서 해당 commit으로 체크아웃 할 수 있다. 

 

tag 지정

  • git tag {tagname} branch/commit hash값/이미 지정된 tag값
    • # git tag secong_tag 1.0.0
    • # git tag third_tag 
      • 현재 브랜치 HEAD에 tag가 추가됨
    • # git tag forth_tag e99ccf52d8a12112bdd1ead30996ab40b6ceabff
    • # git tag fifth_tag master

 

  • git tag의 annotation을 지정하여 tag에 설명을 추가할 수 있다.
    • # git tag -a {tagName} -m "msg"
    • # git tag -v {tagName}

 

  • git push --tags
    • --tags 옵션을 추가함으로써 remote repository에 tag까지 업로드할 수 있다.

'기타 > git' 카테고리의 다른 글

git merge  (0) 2021.07.24
git stash  (0) 2021.07.16
gistory .git 디렉토리 분석  (0) 2021.07.11
git / github  (0) 2021.07.11
git 기본 명렁어  (0) 2021.07.11

gistory를 설치하여 .git 디렉토리 내용 분석

# pip3 install gistory

 

https://pypi.org/project/gistory/

 

gistory

Tracking your .git changed history

pypi.org

 

git 로컬디렉토리의 .git폴더 내에서 gistory 명령어 실행

 

  • git add 명령어를 통해 test.txt파일을 staging area로 옮겨줌.
    • index = 파일의 이름이 담겨있음 
      • ./index라는 파일에  hash값과 test.txt파일의 매핑관계가 저장되어 있다. 
    • Object = 파일의 내용이 담겨있음
      • ./Object/78/{hash} 파일이 생성

 

 

 

  • 다른 파일이름에 같은 내용을 staging area에 옮김
    • test1.txt 파일과 test3.txt파일이 가리키는 Object가 78981922613b2afb6025042ff6bd878ac1994e85 로 동일한 hash값인걸 확인 할 수 있다.
      • git은 파일의 이름이 달라도 파일의 내용이 같으면 같은 Object파일을 가리킴

 

 

Tree 개체

  • 파일이름이 저장되는 개체

 

blob

  • 파일내용이 저장되는 개체

 

 

Working Directory / index,staging area, cache / repository 

'기타 > git' 카테고리의 다른 글

git tag  (0) 2021.07.23
git stash  (0) 2021.07.16
git / github  (0) 2021.07.11
git 기본 명렁어  (0) 2021.07.11
git/github 설치 및 초기화  (0) 2021.01.21

로컬과 원격저장소

  • # git remote(-v)
    • remote repository에 조회하기
  • # git init --bare remote
    • 로컬에 원격 저장소 생성
  • 로컬 remote 저장소
    • git remote add origin ssh://[remote저장소 username]@[remote저장소 IP]/저장소 path 
      • # git remote add origin ssh://git@{192.168.1.10}/home/git/remote/
  • # git remote add origin https://github.com/fastwon1/jaon.git
    • 원격저장소 URL을 origin이라는 이름으로 추가
  • # git push origin master
    • origin에 master 브랜치의 내용을 push
    • remote repository에 밀어넣기
  • # git pull origin master
    • origin을 내 repository의 master 브랜치로  download  / merge
    • 현재 내가 작업하고 있는 내용은 사라짐
  • # git fetch origin master
    • 동기화시키지 말고 origin을 내 repository의 master 브랜치로 가지고옴(원격저장소로부터 파일만 다운로드 받음)
      • 장점
        • 지역저장소와 원격저장소간의 diff를 확인할 수 있음
        • # git diff HEAD origin/master
      • fetch 내용을 특정 브랜치에서 확인할 수 있다
        • # git checkout origin/master
        • # git checkout FETCH_HEAD
  • # git clone
    • remote repository의 내용을 현재 디렉토리에 복사
    • origin이라는 remote repository가 자동으로 등록된다

 

협업

  • local repository의 변경사항이 있는데 remote repository는 변경이 없는경우
    • git push로 해결
  • local repository는 변경사항이 없는데 remote repository가 변경사항이 경우
    • git pull로 동기화 후 push
  • local repository도 변하고 remote repository도 변한 경우
    • pull request
      • 협업 대상 repository fork하기
      • fork 해온 곳에서 clone 하기
      • branch를 만들고 작성하고자하는 코드 commit 작성
      • push 권한주기(Manage access(collaborator) 추가하기) 또는 pull request 요청
      • 해당 branch 삭제 
    • merge
      • fast-forward merge
      • 3-way merge
        • merge의 결과인 새로운 merge commit이 생성
    • rebase
      • 현재 작업하고 있는 branch의 base를 옮김
        • base =  현재 작업하고 있는 branch와 합치려는 branch의 공통조상
        • 병합하고자 하는 master branch의 최신 commit으로 base를 옮김

 

 

Troubleshooting)

  • github에 처음 push하려고 할때 아래와 같음 error 발생시
    • remote: Permission to ~~~~~
  • git push https://[아이디]:[비밀번호]@github.com/[아이디]/[레포지토리].git
아이디: not-working
비번: 123456
repository: test
  
 -> git push https://not-working:123456@github.com/not-working/test.git

 

 

 

 

 

Set up Git - GitHub Docs

To use Git on the command line, you'll need to download, install, and configure Git on your computer. You can also install GitHub CLI to use GitHub from the command line. For more information on GitHub CLI, see the GitHub CLI documentation. If you want to

docs.github.com

 

[141] 오픈소스를 쓰려는 자, 리베이스의 무게를 견뎌라

오픈소스를 쓰려는 자, 리베이스의 무게를 견뎌라

www.slideshare.net

 

'기타 > git' 카테고리의 다른 글

git tag  (0) 2021.07.23
git stash  (0) 2021.07.16
gistory .git 디렉토리 분석  (0) 2021.07.11
git 기본 명렁어  (0) 2021.07.11
git/github 설치 및 초기화  (0) 2021.01.21

git add/commit

  • # git add <파일명>
    • # git add .
      • 디렉토리에 있는 파일 전부를 Staging Area로 올림 
      • Working Directory에 있는 파일들을 Staging Area로 올림
  • # git status
    • Staging 상태확인
  • # git commit -m "해당commit에 대한 설명"
    • 버전 생성
  • # git log
    • 버전 확인
  • # git commit -am "해당 commit에 대한 설명"
    • add와 commit을 동시에 진행
      • 단, 한번이라도 commit을 한 대상에 대해서만 가능

 

local repository를 github에 push

  • # git remote add origin https://github.com/fastwon1/jaon.git
    • 원격저장소를 origin이라는 이름으로 추가
  • # git branch -M main
    • master branch 이름을 main branch로 변경
      • 2020년 10월 이후 master라는 용어폐기
  • # git push -u origin main
    • 내 repository의 main 브랜치를 origin의 main 브랜치로 push
  • # git remote rm prac1
    • 원격저장소 prac1을 삭제

 

git reset

  • 되돌린 버전 이후의 버전은 모두 사라짐
    • # git reset --hard HEAD^
      • 현재 수정중이던 Working directory의 내용도 HEAD이전 내용으로 되돌아 간다
        • Staging Area와 작업중인 Working directory의 내용이 삭제
    • # git reset --mixed HEAD^
      • default 옵션
      • Staging Area에 올라와있던 내용은 사라지며 작업중이던 Working Directory의 내용은 유지
    • # git --soft HEAD^
      • Repository의 HEAD 이전 버전으로 commit한것만 되돌린다
        • Staging Area와 Working directory의 내용은 유지
    • # git reset --hard ORIG_HEAD
      • reset한 내용을 취소

  • # git reflog
    • 작업했던 commit들이 기록조회

 

Branch

  • master branch
    • 다른 branch들이 뻗어나가는 시초 branch

  • # git branch
    • branch 리스트확인
    • * master
      • 현재 master branch를 사용중임을 표시

 

  • # git branch test_branch
    • test branch라는 브랜치 생성

 

  • # git checkout test_branch
    • branch 변경

 

  • # git checkout -b test_branch
    • branch 생성 후 branch switch

 

  • # git diff
    • 변경 내역들간의 비교
      • 두 commit간 비교
        • # git diff <비교대상commit> <기준commit>
      • 원격 repository와 local repository간의 비교
        • # git diff <비교 대상 branch이름> origin/<branch 이름>

 

  • # git log
    • 버전확인
    • # git log --all --decorate --graph --oneline
  •  
  • reset vs revert
    • reset : 시간을 과거의 특정 사건으로 되돌림
    • revert : 현재를 기준으로 과거의 사건들을 없던일로 되돌림
      • 되돌린 버전 이후의 버전들은 모두 유지

 

git reset option

Working directory
Working tree
Working copy
index
staging area
cache
repository
history
tree
    git reset --soft
  git reset --mixed
git reset --hard

 

용어

  • HEAD : 현재 작업 중인 branch/commit 중 가장 최근 커밋한 버전
  • ^ : 가장 최근 커밋으로부터 하나 버전 이전으로 되돌림
  • ^^ : 가장 최근 커밋으로부터 두개 버전 이전으로 되돌림

'기타 > git' 카테고리의 다른 글

git tag  (0) 2021.07.23
git stash  (0) 2021.07.16
gistory .git 디렉토리 분석  (0) 2021.07.11
git / github  (0) 2021.07.11
git/github 설치 및 초기화  (0) 2021.01.21

git / github 설치 및 초기화

 

1. 로컬에 git 설치

출처: http://git-scm.com/book/en/v2/Getting-Started-What-is-Git%3F

 

2. 초기화

 

  1. git bash 실행(window)

2. git을 설치한 후 local저장소로 사용할 디렉토리를 만들어서 Git Bash Here를 클릭

  • # git init
    • 로컬저장소의 초기화 명령
    • 현재 디렉토리를 버전관리하기 위함
  •  

'기타 > git' 카테고리의 다른 글

git tag  (0) 2021.07.23
git stash  (0) 2021.07.16
gistory .git 디렉토리 분석  (0) 2021.07.11
git / github  (0) 2021.07.11
git 기본 명렁어  (0) 2021.07.11

+ Recent posts