Programing

git 저장소를 다른 디렉토리로 이동하고 해당 디렉토리를 git 저장소로 만드는 방법은 무엇입니까?

lottogame 2020. 10. 6. 07:45
반응형

git 저장소를 다른 디렉토리로 이동하고 해당 디렉토리를 git 저장소로 만드는 방법은 무엇입니까?


gitrepo1 디렉토리가 있습니다 . 이 디렉토리는 git 저장소입니다.

  • gitrepo1 을 다른 디렉토리 newrepo옮기고 싶습니다 .

  • newrepo 디렉토리 는 git 기록 손실이없는 새 git 저장소 여야하며 gitrepo1 디렉토리를 포함해야합니다 .

  • gitrepo1 디렉토리 색인이 없는 디렉토리 ( newrepo 내부 ) .git여야합니다. 즉, 더 이상 독립적 인 git 저장소 또는 하위 모듈이 아니어야합니다.

어떻게 할 수 있습니까?


아주 간단합니다. Git은 디렉토리 이름이 무엇인지 신경 쓰지 않습니다. 안에있는 것만 신경 쓰죠. 따라서 간단하게 다음을 수행 할 수 있습니다.

# copy the directory into newrepo dir that exists already (else create it)
$ cp -r gitrepo1 newrepo

# remove .git from old repo to delete all history and anything git from it
$ rm -rf gitrepo1/.git

저장소가 크고 기록이 긴 경우 복사본이 상당히 비쌉니다. 쉽게 피할 수 있습니다.

# move the directory instead
$ mv gitrepo1 newrepo

# make a copy of the latest version
# Either:
$ mkdir gitrepo1; cp -r newrepo/* gitrepo1/  # doesn't copy .gitignore (and other hidden files)

# Or:
$ git clone --depth 1 newrepo gitrepo1; rm -rf gitrepo1/.git

# Or (look further here: http://stackoverflow.com/q/1209999/912144)
$ git archive --format=tar --remote=<repository URL> HEAD | tar xf -

를 만든 후에는 원하는 경우 안에 newrepo넣을 gitrepo1수 있습니다 newrepo. 절차를 변경하지 않고 gitrepo1다시 작성하는 경로 만 변경합니다 .

참고 URL : https://stackoverflow.com/questions/19097259/how-to-move-a-git-repository-into-another-directory-and-make-that-directory-a-gi

반응형