git명령어

GIT log

2022. 6. 21. 11:21
반응형

log

  • git 이력
git log //remote 포함
git log --branches --not --remotes //local
반응형

'Infra > git' 카테고리의 다른 글

GIT status  (0) 2022.06.21
GIT pull  (0) 2022.06.21
Git fetch  (0) 2022.06.21
GIT init  (0) 2022.06.21
GIT 명령어  (0) 2022.04.07

GIT init

2022. 6. 21. 11:19
반응형

init

  • 히스토리 삭제
rm -rf .git commit
  • 새로운 git 설정
git init
반응형

'Infra > git' 카테고리의 다른 글

GIT status  (0) 2022.06.21
GIT pull  (0) 2022.06.21
Git fetch  (0) 2022.06.21
GIT log  (0) 2022.06.21
GIT 명령어  (0) 2022.04.07

GIT 명령어

2022. 4. 7. 15:11
반응형

GIT 자주 사용하는 명령어

init

  • 히스토리 삭제
rm -rf .git commit
  • 새로운 git 설정
git init

log

  • git 이력
git log //remote 포함
git log --branches --not --remotes //local

fetch

  • remote repository에 변경사항을 local repository로 가져만 옴
git fetch

pull

  • remote repository에 변경사항을 local repository로 fetch 후 merge
git pull

status

  • branch 변경 상태 확인
git status

remote

  • 연결된 저장소 확인
git remote -v
git remote remove origin //연결 삭제
git remote add origin {brach} //신규 연결

checkout

  • local repository로 동기화된 브랜치로 workspace 변경
git checkout -t feature/{branch} //new:-t, 기존:-b

add (staged area)

  • 수정한 파일을 unstaged -> staged 로 이동 (commit 전 실행)
git add --all or add . or add {filename}
git reset HEAD {filename} or 파일명 없을 경우 전체 //staged -> unstaged

restore

  • commit 전 unstatged에 존재하지 않는 수정된 파일을 HEAD revision 으로 되돌림
git restore {filename}

clean

  • untracked file 삭제해야 할 경우
git clean -f // untracked file
git clean -d // untracked folder
git clean -fd // file 및 folder 까지

stash

  • workspace에서 수정 중인 파일 임시 저장
git stash save {stashname}
git stash list  //목록 보기
git stash clear  // 전체 삭제
git stash apply stash@{0}  //저장된 stash 불러오기
git stash pop  //가장 마지막에 save한 stash 불러오기

commit

  • local 작업 내역 저장 (원격 저장소 push 전 수행)
git commit -m "commit init"
git commit --amend  //message vi 모드
git commit --amend -m "메세지 변경"  //message 변경
git reset HEAD^ or git reset {commit id} //local commit 취소
git commit --allow-empty -m "empty commit"  //empty commit

push

  • local repository에 commit 이력을 remote push
git push origin {branch}
git push origin {branch} -f  // remote force push

cherry-pick

  • 다른 브랜치 commit hash 가져오기
git cherry-pick {5775401d}
git cherry-pick f2abff5^..8e2fa35  //범위 지정하여 가져오기 (f2abff5~ 8e2fa35 commit 까지)

rebase

  • commit 된 이력을 1개의 새로운 commit 으로 합칠 때(되감기)
    • 공동 작업 브랜치에는 되도록 수행하지 말 것.
    • 개인 브랜치는 commit history 깔끔하게 관리하고 싶을 경우 수행 추천.
git rebase -i HEAD~2,3 //합칠 개수
git rebase -i HEAD~3 //마지막부터 몇번째 commit 까지 개수
​
 pick -> squash 변경 후 vi 저장 //합칠경우 (lastest 부터 역순으로!!!!)
 pick -> drop 변경 후 vi 저장   //특정 commit 삭제
​
git log //합쳐진 commit 확인 or git reflog
git commit -m "주석 수정" //합친 후 주석 수정
git rebase --continue //rebase 완료  
git rebase --abort //rebase 롤백시 
git push -f origin {branch} //force remote push

merge

  • 서로 다른 branch 병합하기
git checkout {branchA}
git merge {branchB}  //A에 B 변경 내역을 병합
git merge --continue // 병합 저장
git merge --abort // 병합 롤백
​
git checkout {branchA} {filename}  //A branch 에서 file 1개만 merge
반응형

'Infra > git' 카테고리의 다른 글

GIT status  (0) 2022.06.21
GIT pull  (0) 2022.06.21
Git fetch  (0) 2022.06.21
GIT log  (0) 2022.06.21
GIT init  (0) 2022.06.21

+ Recent posts

반응형