💽 CICD/Git

[Git] 커밋 히스토리 조회 & 되돌리기

heywantodo 2023. 3. 24. 17:07
728x90
반응형

Git 커밋 히스토리 조회 & 되돌리기

Git 히스토리 조회

 

Git log

  • 명령어를 통해 히스토리를 조회
git clone https://github.com/Jeonghy0517/2023BucketList
git log

Git log 옵션

-p 내역을 원하는 숫자 만큼 조회
--stat 통계 정보 조회
--pretty=[출력형식] oneline, short, full, fuller 출력 형식 지정
--pretty=format :"%h - %an, %ar : %s" 출력 포맷 변경
--pretty=format : --graph 아스키 코드로 그래프 출력 
--no-merges 머지 커밋을 제외
--since=날짜 명시한 날짜 이후의 커밋만 검색
--until = 날짜 명시한 날짜 이전의 커밋만 검색

Git log 예시

#조회 제한 조건
git log --pretty=oneline
git log --pretty=format:"%h - %an, %ar : %s"

git log --since=2.weeks
git log --until-2.weeks 

#텍스트 조회
git log -S function_name

#특정 파일
git log [파일명]

 

Git 되돌리기

⚠ 한 번 되돌리면 복구할 수 없기 때문에 주의

 

커밋 재작성

echo "hello world" > hello.txt

git add hello.txt
git commit -m "first commit"

#커밋 수정
git log
git commit --amend

파일 상태를 Unstage로 변경하기

echo "hello world git" > hello2.txt

git add .
git status

#기존 hello.txt 파일을 Unstage로 변경 
git reset HEAD hello.txt

Modified 파일 되돌리기

  • 파일 수정
echo "hello world git" >> hello.txt 
cat hello.txt

  • Modified 파일 되돌리기
git checkout -- hello.txt
git status

  • 파일 확인하기
cat hello.txt

 

 

참조

http://www.dreamy.pe.kr/zbxe/CodeClip/3766623

https://git-scm.com/book/ko/v2/Git-%EB%8F%84%EA%B5%AC-%ED%9E%88%EC%8A%A4%ED%86%A0%EB%A6%AC-%EB%8B%A8%EC%9E%A5%ED%95%98%EA%B8%B0

 

728x90
반응형