git 자주 찾아보는 내용 정리

석헌주·2021년 11월 24일
0

remote branch 받아오기

pull request conflict 해결하기

  1. 현재 branch에서 작업중이던 내용을 commit
  2. 새롭게 update된 remote의 release-v4.4.2 branch를 local 의 release-v4.4.2 와 동기화 git fetch origin && git checkout release-v4.4.2 && git pull origin release-v4.4.2
  3. 현재 작업 중인 branch로 다시 전환 git checkout DBT-332-integration-test
  4. local에서 동기화 한 release-v4.4.2 의 내용을 현재 작업중인 branch로 병합 git merge release-v4.4.2
  5. conflict 해결 후 commit & push git commit git push origin DBT-332-integration-test

git tag

  • tag 조회
    • 전체 태그 조회 - git tag
    • 조건명으로 태그 조회 - git tag -l v1.1.*
    • 특정 태그 조회 - git tag v1.1.0
  • tag 삭제
    • 로컬에 있는 태그 삭제 - git tag -d {태그명}
    • remote에 있는 태그 삭제 - git push --delete origin {태그명}
  • 로그확인
    • tag, graph 함께 확인 - git log --oneline --graph --tags

http://minsone.github.io/git/git-addtion-and-modified-delete-tag

원하는 폴더 이름으로 git clone 받기

  • git clone git@github.com:whatever folder-name

branch 이름 변경하기

  1. 현재 브랜치의 이름을 변경하기 : git branch -m new-name
  2. 다른 브랜치의 이름을 변경하기: git branch -m old-name new-name

https://multiplestates.wordpress.com/2015/02/05/rename-a-local-and-remote-branch-in-git/

branch 삭제하기

  • 삭제: git branch --delete feature-01
  • 강제 삭제: git branch -D feature-01
  • remote branch 삭제: git push origin :feature-01

remote repository 바꾸기

  • remote url 이름 확인 : git remote -v
  • remote repository 변경 : git remote set-url {URL} {repository name(ex:origin)} {주소}

브랜치 끼리 비교하기

  • git diff <masterbranch_path> <remotebranch_path>
  • ex) git diff master origin/master

https://stackoverflow.com/questions/1800783/how-to-compare-a-local-git-branch-with-its-remote-branch

  • conflict 나는지 확인하려면 —check option 추가

특정 커밋과 merge 하고 싶을 경우 (cherry pick)

특정 커밋 내용을 되돌리고 새로운 커밋기록으로 남기고 싶을 때 (git revert)

좀 더 알아보고 주의해서 사용해야 함

https://www.devpools.kr/2017/02/05/초보용-git-되돌리기-reset-revert/

git revert 1hf3hh

github에서 jenkins build status 보여주는 설정

https://stackoverflow.com/questions/14274293/show-current-state-of-jenkins-build-on-github-repo

stash list에 있는 항목들을 삭제하려고 할 때

git stash clear

특정 이름으로 stash 할 때

git stash save "my name"

stash 저장한 stash 적용하고 저장 목록에서 지울 때

git stash pop stash@{n}

git tracking 취소하기 (git add 취소)

https://gmlwjd9405.github.io/2018/05/25/git-add-cancle.html

git reset HEAD [file]

tracked file list를 볼 때

git ls-files

remote branch를 포함한 브랜치 전체 리스트를 보고싶을 때

git branch -a

git commit —amend 잘못했을 때

# 복구할 버전 확인
git reflog

# Move the current head so that it's pointing at the old commit
# Leave the index intact for redoing the commit.
# HEAD@{1} gives you "the commit that HEAD pointed at before 
# it was moved to where it currently points at". Note that this is
# different from HEAD~1, which gives you "the commit that is the
# parent node of the commit that HEAD is currently pointing to."
git reset --soft HEAD@{1}

# commit the current tree using the commit details of the previous
# HEAD commit. (Note that HEAD@{1} is pointing somewhere different from the
# previous command. It's now pointing at the erroneously amended commit.)
git commit -C HEAD@{1}

https://stackoverflow.com/a/1459264

tracked file list를 뽑아보고 싶을 때

  • git ls-tree -r {branch name} --name-only
    • ex) git ls-tree -r gitignore --name-only

file 하나만 원상태로 돌리고 싶을 때

git checkout file/path/you/want/

profile
백엔드 개발자

0개의 댓글