본문 바로가기
여러 기록

Github git mv를 이용해 폴더 또는 파일 이동하기

by 두 그루 2023. 11. 2.

깃헙에서 history를 유지한 채로 파일을 이동하는 방법은 아래 사진처럼 깃헙에서 파일명을 수정하는 방법이 있다.

 

 

하지만, 위 방식으로는 한꺼번에 많은 파일과 폴더를 이동시킬 수 없다. 이럴 땐 특정 명령어를 이용하여 해결할 수 있다. 파일명을 다른 파일명으로 바꾸거나, 폴더를 다른 폴더로, 폴더를 다른 디렉토리로, 여러 소스를 한꺼번에, 이동하는 방법은 아래와 같다.

 

1) 파일명 변경하기

git mv [기존 파일 이름] [변경할 파일 이름]

 

 

2) a 폴더를 b 폴더로 이동하기

git mv [a 폴더 이름] [b 폴더 이름]

 

 

3) a 폴더를 다른 디렉토리로 이동시키기

git mv [이동할 폴더 명] [목적지 디렉토리]

예) testFolder 폴더를 상위 디렉토리로 이동

git mv testFolder ..

 

 

4) 여러 소스를 한꺼번에 이동시키기

git mv [이동할 소스1] [이동할 소스2] ... [목적지 디렉토리]

예) 현재 디렉토리의 모든 소스를 상위 디렉토리로 이동

git mv * ..

 

 

깃헙에서 history를 확인하면 폴더가 삭제되고 재생성된 것이 아니라, history는 유지한 채로 rename된 것을 확인할 수 있다.

 


옵션이나 자세한 내용은 공식 문서에서 확인할 수 있다.

https://git-scm.com/docs/git-mv

 

Git - git-mv Documentation

Each time a superproject update moves a populated submodule (e.g. when switching between commits before and after the move) a stale submodule checkout will remain in the old location and an empty directory will appear in the new location. To populate the s

git-scm.com

 

추가

repository 이동

https://yoshikixdrum.tistory.com/310

 

[GIT] Git Repository 옮기기

Github를 사용하면서 조직을 변경해야 할 상황이 와서 Repository를 새로운 조직의 Repository로 옮기기 위해 작업을 진행했습니다. 사실 간단하게 하자면 기존 코드를 새로운 Repository에 복사해서 옮겨

yoshikixdrum.tistory.com

https://letzgorats.tistory.com/entry/Github%EA%B9%83%ED%97%99-Repository%EB%A0%88%ED%8C%8C%EC%A7%80%ED%86%A0%EB%A6%AC-%EC%9D%B4%EB%8F%99%ED%95%98%EB%8A%94-%EB%B0%A9%EB%B2%95-clonemirror

 

[Github/깃헙] Repository(레파지토리) 이동하는 방법 - clone/mirror

Github에서 Organization이나 다른 레포에서 진행했던 레파지토리를 commit 등의 기록과 함께 또 다른 내 개인 레포로 옮기고 싶을 때는 어떻게 할까? CMD창을 열어 쉽게 해결할 수 있다. git clone --mirror {

letzgorats.tistory.com

 

'여러 기록' 카테고리의 다른 글

Github 커밋 유지한 채로 repository 복사하기  (0) 2023.11.02
갑자기 CocoaPods not installed.  (0) 2023.10.20
Font Awesome 5 (KIT CODE) 모음  (0) 2023.03.11
vscode macOS shortcuts  (0) 2023.02.20

댓글