Mercurial 프로젝트를 Git으로 변환
이 질문에는 이미 답변이 있습니다.
수은 프로젝트를 git 프로젝트로 변환해야하지만 커밋 기록을 그대로 유지하고 싶습니다. 내 현재 솔루션은 hg 관련 파일을 제거한 다음 git init && 필요한 파일을 수동으로 추가하는 것이었지만 기록을 유지하지는 못했습니다. 이것에 대한 해결책이 있습니까?
빠른 내보내기를 사용해보십시오 .
cd ~
git clone https://github.com/frej/fast-export.git
git init git_repo
cd git_repo
~/fast-export/hg-fast-export.sh -r /path/to/old/mercurial_repo
git checkout HEAD
이 SO 질문도 살펴보십시오 .
4.6 미만의 Mercurial 버전을 사용하는 경우 adrihanu 가 도움을 받았습니다.
그의 의견에 명시된 바와 같이 : . "오류가 당신은 당신의 의욕을 업데이트하거나 자식 체크 아웃 태그 / v180317 내부 ~ / 빠른 수출 디렉토리를 실행하여 빠른 수출을 다운 그레이드해야하는"경우에 당신은 의욕 <4.6을 사용하고 당신이있어 "을 (를) 찾을 수 없습니다 revsymbol " .
Ok 나는 마침내 이것을 해결했다. 이것은 Windows에서 TortoiseHg를 사용하고 있습니다. 사용하지 않으면 명령 행에서 수행 할 수 있습니다.
- TortoiseHg 설치
- 탐색기에서 빈 공간을 마우스 오른쪽 버튼으로 클릭하고 TortoiseHg 설정으로 이동하십시오.
- 사용
hggit
:
명령 행을 열고 빈 디렉토리를 입력하십시오 .
git init --bare .git
(맨손으로 리포지를 사용하지 않으면 다음과 같은 오류가 발생합니다.abort: git remote error: refs/heads/master failed to update
cd
Mercurial 저장소로hg bookmarks hg
hg push c:/path/to/your/git/repo
Git 디렉토리에서 :
git config --bool core.bare false
(왜 냐고 묻지 말아라. "작업 트리"에 관한 것. Git은 심각하지 않다. Git을 사용하는 것보다 실제 코드를 작성하는 것이 더 쉽다고 맹세한다.)
잘 작동하면 새 git 저장소에서 맨손으로 밀어 넣을 수 있습니다.
기존 머큐리얼 리포지토리를 'GitHub'리포지토리로 가져 오려면 여기서 [로그인 필요] 에서 GitHub 임포터를 사용 하면 됩니다. 빠른 내보내기 등으로 더 이상 혼란스럽지 않습니다 (매우 훌륭한 도구이지만)
당신은 모든 얻을 것이다 커밋 , 지점 및 태그 그대로. 한 가지 더 멋진 점은 작성자의 이메일 ID 도 변경할 수 있다는 것입니다 . 아래 스크린 샷을 확인하십시오.
Mercurial을 Git으로 변환 한 경험에 대한 메모.
1. hg 빠른 수출
hg-fast-export 사용에 실패했으며 위에서 언급 한 것처럼 --force가 필요했습니다. 다음 으로이 오류가 발생했습니다.
오류 : 'refs / heads / stable'참조를 잠글 수 없음 : 'refs / heads / stable / sub-branch-name'이 있습니다. 'refs / heads / stable'을 만들 수 없습니다
hg-fast-export가 완료되면 나는 잘린 레포로 끝났다. 이 저장소에는 고아 지사가 거의 없으며 hg-fast-export에는 다소 이상적인 저장소가 필요하다고 생각합니다. 이 모든 것이 가장자리에서 약간 거칠어 보였으므로 Kiln Harmony ( http://blog.fogcreek.com/announcing-kiln-harmony-the-future-of-dvcs/ ) 로 옮겼습니다.
2. 킬른
위에서 제안한대로 Kiln Harmony는 프리 티어 계정에 존재하지 않는 것 같습니다. Git 전용 및 Mercurial 전용 저장소 중에서 선택할 수 있으며 전환 옵션이 없습니다. 지원 티켓을 모았으며 답장하면 결과를 공유 할 것입니다.
3. hg-git
Hg-Git 머큐리얼 플러그인 ( http://hg-git.github.io/ )이 저에게 효과적이었습니다. Mac OSX의 참고 사항 다음과 같이 macports를 통해 hg-git을 설치했습니다.
- sudo 포트 설치 python27
- sudo 포트 선택 --python python27
- sudo port install py27-hggit
- vi ~/.hgrc
.hgrc needs these lines:
[ui]
username = Name Surname <me@mydomain.com>
[extensions]
hgext.bookmarks =
hggit =
I then had success with:
hg push git+ssh://git@bitbucket.org:myaccount/myrepo.git
4. Caveat: Know your repo
All the above are blunt instruments and I only pushed ahead because it took enough time to get the team to use git properly.
Upon first pushing the project per (3) I ended up with all new changes missing. This is because this line of code must be viewed as a guide only:
$ hg bookmark -r default master # make a bookmark of master for default, so a ref gets created
The theory is that the default branch can be deemed to be master when pushing to git, and in my case I inherited a repo where they used 'stable' as the equivalent of master. Moreover, I also discovered that the tip of the repo was a hotfix not yet merged with the 'stable' branch.
Without properly understanding both Mercurial and the repo to be converted, you are probably better off not doing the conversion.
I did the following in order to get the repo ready for a second conversion attempt:
hg update -C stable
hg merge stable/hotfix-feature
hg ci -m "Merge with stable branch"
hg push git+ssh://git@bitbucket.org:myaccount/myrepo.git
After this I had a verifiably equivalent project in git, however all the orphaned branches I mentioned earlier are gone. I don't think that is too serious, but I may well live to regret this as an oversight. Therefore my final thought is to keep the original anyway.
Edit: If you just want the latest commit in git, this is simpler than the above merge:
hg book -r tip master
hg push git+ssh://git@bitbucket.org:myaccount/myrepo.git
From:
http://hivelogic.com/articles/converting-from-mercurial-to-git
Migrating
It’s a relatively simple process. First we download fast-export (the best way is via its Git repository, which I’ll clone right to the desktop), then we create a new git repository, perform the migration, and check out the HEAD. On the command line, it goes like this:
cd ~/Desktop
git clone git://repo.or.cz/fast-export.git
git init git_repo
cd git_repo
~/Desktop/fast-export/hg-fast-export.sh -r /path/to/old/mercurial_repo
git checkout HEAD
You should see a long listing of commits fly by as your project is migrated after running fast-export. If you see errors, they are likely related to an improperly specified Python path (see the note above and customize for your system).
That’s it, you’re done.
Another option is to create a free Kiln account -- kiln round trips between git and hg with 100% metadata retention, so you can use it for a one time convert or use it to access a repository using whichever client you prefer.
I had a similar task to do, but it contained some aspects that were not sufficiently covered by the other answers here:
- I wanted to convert all (in my case: two, or in general: more than one) branches of my repo.
- I had non-ASCII and (being a Windows user) non-UTF8-encoded characters (for the curious: German umlaute) in my commit messages and file names.
I did not try fast-export and hg-fast-export, since they require that you have Python and some Mercurial Python modules on your machine, which I didn't have.
I did try hg-init with TortoiseHG, and this answer gave me a good start. But it looked like it only converts the current branch, not all at once (*). So I read the hg-init docs and this blog post and added
[git]
branch_bookmark_suffix=_bookmark
to my mercurial.ini, and did
hg bookmarks -r default master
hg bookmarks -r my_branch my_branch_bookmark
hg gexport
(Repeat the 2nd line for every branch you want to convert, and repeat it again if you should happen to do another commit before executing the 3rd line). This creates a folder git
within .hg
, which turns out to be a bare Git repo with all the exported branches. I could clone this repo and had a working copy as desired.
Or almost...
Running
git status
on my working copy showed all files with non-ASCII characters in their names as untracked files. So I continued researching and followed this advice:
git rm -rf --cached \*
git add --all
git commit
And finally the repo was ready to be pushed up to Bitbucket :-)
I also tried the Github importer as mentioned in this answer. I used Bitbucket as the source system, and Github did quite a good job, i.e. it converted all branches automatically. However, it showed '?'-characters for all non-ASCII characters in my commit messages (Web-UI and locally) and filenames (Web-UI only), and while I could fix the filenames as described above, I had no idea what to do with the commit messages, and so I'd prefer the hg-init approach. Without the encoding issue the Github importer would have been a perfect and fast solution (as long as you have a paid Github account or can tolerate that your repo is public for as long as it takes to pull it from Github to your local machine).
(*) So it looked like before I discovered that I have to bookmark all the branches I want to export. If you do and push to a bare (!) repo, like the linked answer says, you get all the branches.
This would be better as a comment, sorry I do not have commenting permissions.
@mar10 comment was the missing piece I needed to do this.
Note that '/path/to/old/mercurial_repo' must be a path on the file system (not a URL), so you have to clone the original repository before. – mar10 Dec 27 '13 at 16:30
This comment was in regards to the answer that solved this for me, https://stackoverflow.com/a/10710294/2148757 which is the same answer as the one marked correct here, https://stackoverflow.com/a/16037861/2148757
이것은 커밋 히스토리를 그대로 유지하면서 hg 프로젝트를 git으로 옮겼습니다.
참고 URL : https://stackoverflow.com/questions/16037787/convert-mercurial-project-to-git
'Programing' 카테고리의 다른 글
사전을 JSON으로 변환 (0) | 2020.03.31 |
---|---|
랙 미들웨어 란 무엇입니까? (0) | 2020.03.31 |
교차 ()의 반대 (0) | 2020.03.31 |
코어 당 최적 스레드 수 (0) | 2020.03.31 |
cURL을 사용하여 CORS 요청을 어떻게 디버깅 할 수 있습니까? (0) | 2020.03.31 |