본문 바로가기

Git

전체 Git Repository가 아닌 일부 특정폴더의 파일들만 이전 버전으로 돌리는 방법 (Reset With a Path)

1. 상황

 

우리 회사는 각각의 프로젝트를 빌드한 모듈들을 하나의 패키지로 만든다.

이런 모듈들을 모은 패키지를 하나의 Git Repsitory로 버전관리를 하는데

패키지를 만들어 테스트를 하던 도중 버그가 발견되어

특정 모듈만 수정이 필요하였다.

 

특정 모듈 프로젝트를 수정하고 빌드하여 패키지 파일을 수정할 때

배포 자동화 스크립트 동작을 위하여

수정이 필요한 모듈의 파일만 이전 버전으로 되돌릴 필요가 있었다.

 

여러 모듈들이 동시에 수정된 내용이 하나의 커밋으로 반영이 된 상황이었다. 

그리고 이 커밋의 내용 중 일부는 남기고 일부는 이전 커밋으로 돌려야 할 필요가 있었다.

이럴 때 어떤 Git 명령어를 사용하면 될지 찾아보았다.

 

2. 실행해야 하는 명령어

 

아래의 두 명령어를 실행하여 특정 폴더만 이전 버전으로 돌리고 재커밋을 하였다.

처음에는 체크아웃만 하면 될 줄 알았으나 Added와 Deleted된 파일들은 indexed되어 이전 버전 상태로 Add 및 Delete가 되지 않아 reset을 먼저 해줘야 한다. 

// git reset [커밋 아이디] -- [경로]
git reset 583f36ab -- ./Channel
// git checkout [커밋 아이디] -- [경로]
git checkout 583f36ab -- ./Channel

 

3. 참고했던 사이트

 

https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting

 

Resetting, Checking Out & Reverting | Atlassian Git Tutorial

Compare the most common configurations of git reset, git checkout, and git revert. Walk away with confidence to navigate your repo using these commands.

www.atlassian.com

https://git-scm.com/book/en/v2/Git-Tools-Reset-Demystified

 

Git - Reset Demystified

So let’s think about what just happened. You undid your last commit, the git add and git commit commands, and all the work you did in your working directory. It’s important to note that this flag (--hard) is the only way to make the reset command dange

git-scm.com

https://stackoverflow.com/a/30875442

 

Restore a deleted folder in a Git repo

I have deleted all the contents inside a folder and the folder is empty. I still had a copy in my remote repo. But when I did a git pull it didn't put back the deleted files isn't is supposed to do...

stackoverflow.com