457 words
2 minutes
[Git] commit, push 제외 자주쓰는 git 명령어들
2021-08-21
2026-02-07

Branch 생성#

Terminal window
git branch

생성한 Branch로 이동#

Terminal window
git switch example
  • branch를 만들면서 현재 branch 변경
Terminal window
git switch -c example2 # c 는 아마 create를 의미

branch 삭제#

Terminal window
git branch -d example
  • merge가 정상적으로 안되는 branch를 강제 삭제할 겨우
Terminal window
git branch -D example
  • 원격 브랜치를 삭제할 경우
git push origin --delete example

파일옮기기, 이름 바꾸기#

단순히 unix mv 명령어를 사용해도 된다.

Terminal window
git mv old_file new file

커밋내역 확인하기#

log를 통해 이전 커밋 내역을 확인한다.

Terminal window
git log

커밋내역 삭제하기#

Terminal window
git reset HEAD~n 최근 내역 n개 삭제
git log # 삭제된 커밋 확인

변경사항 복원하기#

restore : 변경 내역이 있는 파일을 복원할 수 있다.

Terminal window
git restore a_file
  • stage 된 파일 복원
Terminal window
git restore --staged a_file

branch 합치기(merge)#

  • 여기서는 현재 branch의 commit을 대상이 되는 branch의 commit까지 옮기는 작업인 Fast Forward Merge 만 다룬다.
  • Fast Forward Merge는 중간에 다른 커밋이 추가되면 충돌 오류가 발생한다.
Terminal window
git switch example
git merge example2

References#

[Git] commit, push 제외 자주쓰는 git 명령어들
https://yjinheon.netlify.app/posts/02de/git/git-log/
Author
Datamind
Published at
2021-08-21
License
CC BY-NC-SA 4.0