상세 컨텐츠

본문 제목

[Git] Merge 되돌리기

Operating System (OS) & Network & VCS/Git

by 찌니씨 2022. 10. 11. 13:14

본문

git

현재 상태 체크

 

$ git status //git 상태 확인

$ git stash (save) //staging 에 있는 내용과 아직 staging에 들어가지 않은 변경사항을 모두 저장

변경, 추가된 파일 확인

또는 staging 체크

 

원격 로그 확인
$ git log --oneline --graph //원격 로그를 그래프로 보여줌

 

git-log

 

$ git log --merges	//병합했던 로그확인

1bbf241 (HEAD -> develop, origin/develop) Merge branch 'staging/staging-0.1' into
develop

 

git-log-merges

 

충돌 난 부분은 원래의 코드로 되돌리고 다시 고쳐보려고 할 때 “ours” 나 “theirs” 말고도 “base” 버전의 내용까지 제공

$ git checkout --conflict=diff3

 

계속 사용하고 싶다면

 

$ git config --global merge.conflictstyle diff3

 

git reset: commit 취소
git revert: commit 되돌리기
git commit --amend: commit 덮어쓰기
reset:  Commit message가 남지 않는다
revert: 
Commit 추가 (History를 통해 삭제, 수정한 내용이 이력이 남는다)

 


reset (바로 이전 commit, commit_id 되돌리기)

❗ 공동작업을 할 때에는 주의를 요함

로컬 저장소의 상태를 커밋 이전 상태로 강제 변경 (HEAD 위치 바뀜)

$ git reset --hard HEAD // HEAD를 기점으로 working directory를 원격 저장소의 마지막 commit상태로 reset

$ git reset --hard [commit_id] // commit_id의 commit을 취소하고 unstaged 상태로 working디렉토리에서 삭제
$ git reset --soft HEAD^ // 바로 이전 commit을 취소하고 해당 파일들은 staged 상태로 working디렉토리에

 

• soft : index 보존( add 한 상태, staged 상태), 워킹 디렉터리의 파일 보존. 즉 모두 보존.
• mixed : index 취소( add 하기 전 상태, unstaged 상태), 워킹 디렉터리의 파일 보존 (기본 옵션)  잘 안 씀
• hard : index 취소( add 하기 전 상태, unstaged 상태), 워킹 디렉터리의 파일 삭제. 즉 모두 취소.


reset (병합, 충돌 파일이 있을 때)

 

$ git show ORIG_HEAD
$ git reset --hard ORIG_HEAD // ORIG_HEAD: 병합이나 커밋이 진행될 때 이전 HEAD를 저장해두는 이름
$ git reset --merge ORIG_HEAD // ORIG_HEAD 기점으로 merge 취소

$ git ls-files --unmerged // unmerge 된 file 확인 → 충돌파일 확인

revert

변경사항을 취소하는 새로운 커밋

 

$ git revert -m 1 HEAD // -m 1 부모가 보호되어야 하는 mainlin은 1임

$ git revert --no-commit 5ac9df2 // 5ac9df2 revert commit message 없이

$ git revert --no-commit HEAD~3.. // revert commit massage 없이 HEAD로 부터 3번째 커밋까지

$ git revert --no-commit master~3..master // revert commit massage 없이 master 3번째 커밋까지

 

reset이나 revert 후 작업

 

$ git status //상태 확인

 

파일 상태를 Unstage로 변경하기

 

$ git reset HEAD file_name

 

되돌려진 상태에서 다시 commit을 하거나 (변경된 파일 commit)

 

$ git commit -m "messages"

$ git push origin [branch name] -f  //force 경고 무시하고 강제로 push
$ git push origin +[branch name] //경고 무시하고 해당 branch를 강제로 push

 

Untracked files, Changes not staged for commit 삭제 (변경된 파일 초기화)

정말 폴더까지 삭제해야 할까? 잘 생각하고 실행하자

 

$ git clean -n //untracked files 확인

git clean -n file_name //file_name 삭제

$ git clean -f // 파일들 삭제
$ git clean -f -d // 디렉터리 삭제
$ git clean -fd //디렉터리(파일) 삭제
$ git clean -f -d -x // 무시된 파일까지 삭제

 

merge를 이전 상태로 돌리고 취소

 

$ git merge --abort //merge 취소

commit --amend

아직 push하지 않은 이전 커밋에 추가로 내용을 덮어씀

( commit까지 ~push 전에만 유효)

 

$ git commit --amend -m "massage"

 

참고

https://git-scm.com/book/ko/v2/Git-%EB%8F%84%EA%B5%AC-%EA%B3%A0%EA%B8%89-Merge

 

Git - 고급 Merge

Merge 작업할 때 공백 처리 옵션을 사용하면 Git이 꽤 잘해준다. 하지만, Git이 자동으로 해결하지 못하는 때도 있다. 이럴 때는 외부 도구의 도움을 받아 해결한다. 예를 들어 Git이 자동으로 해결해

git-scm.com

 

'Operating System (OS) & Network & VCS > Git' 카테고리의 다른 글

[Git] Commit tamplate file  (0) 2022.10.12
[Git] Cherry-pick  (0) 2022.10.11
[Git] Flow 수정, 초기화  (0) 2022.10.07
[Git] Branch 전략 (Git Flow)  (0) 2022.10.07
[Git] commit, push, merge  (0) 2022.10.07

관련글 더보기

댓글 영역