Git remove, revert, reset

이다연·2021년 4월 14일
0

Git & GitHub

목록 보기
6/8

remove files

https://dev.to/coolprobn/remove-files-or-folders-from-remote-git-3l0

revert & reset

https://opensource.com/article/18/6/git-reset-revert-rebase-commands

reset command

e.g.

git reset --hard 7f3d -> commit ID

Pointing to a certain commit. Usually the latest commit. HEAD -> Working directory

3 options of Reset: soft, mixed, hard

changes applied differently to working directory, staging area and repository depending on the mode.

  • Hard reset changes all three areas into certain previous commit. It clears out current working directory, which means, you can't restore it unless you pushed it into remote repository.
  • Soft reset only changes repo, which means HEAD points to previous commit. Working dir, Staging area stay the same as current state.
working: hard
   |
staging: hard mixed  
   |
repo   : hard mixed soft

  1. 과거의 커밋으로 git reset을 한다고 그 이후의 커밋들이 삭제되는 게 절대 아닙니다. 계속 남아있습니다. (reflog로 복원 가능하나 워킹 디렉토리에 커밋하지 않은채 hard 옵션 사용하면 복구불가)
  2. git reset은 과거의 커밋뿐만 아니라 현재 HEAD가 가리키는 커밋 이후의 커밋으로도 할 수 있습니다.

From CODEIT

git log : 커밋 히스토리를 출력

git log --pretty=oneline : --pretty 옵션을 사용하면 커밋 히스토리를 다양한 방식으로 출력할 수 있습니다. --pretty 옵션에 oneline이라는 값을 주면 커밋 하나당 한 줄씩 출력해줍니다. --pretty 옵션에 대해 더 자세히 알고싶으면 이 링크를 참고하세요. 

git show [커밋 아이디] : 특정 커밋에서 어떤 변경사항이 있었는지 확인

git commit --amend : 최신 커밋을 다시 수정해서 새로운 커밋으로 만듦

git config alias.[별명] [커맨드] : 길이가 긴 커맨드에 별명을 붙여서 이후로 별명으로 해당 커맨드를 실행할 수 있도록 설정

git diff [커밋 A의 아이디] [커밋 B의 아이디] : 두 커밋 간의 차이 비교

git reset [옵션] [커밋 아이디] : 옵션에 따라 하는 작업이 달라짐(옵션을 생략하면 --mixed 옵션이 적용됨) 

	(1) HEAD가 특정 커밋을 가리키도록 이동시킴(--soft는 여기까지 수행)

	(2) staging area도 특정 커밋처럼 리셋(--mixed는 여기까지 수행)

	(3) working directory도 특정 커밋처럼 리셋(--hard는 여기까지 수행)

	그리고 이때 커밋 아이디 대신 HEAD의 위치를 기준으로 한 표기법(예 : HEAD^, HEAD~3)을 사용해도 됨

git tag [태그 이름] [커밋 아이디] : 특정 커밋에 태그를 붙임
profile
Dayeon Lee | Django & Python Web Developer

0개의 댓글