Import changes into a git repository from universal diff
I'm trying to import changes from one source control system (proprietary and complicated) into a git repository. I'm doing this currently by running a script that simply syncs to each revision in order and commits this to the git repository, but for various reasons this has become unworkable.
For each revision, I can get a universal diff describing the change. To me it seems that this should be enough to import history to git, but I can't for the life of me figure out how to get git to do this. It looks like I need something in-between git-apply and git-fast-import. Perhaps I should construct the file contents from the previous version and the diff, then use git-fast-import? Or perhaps I should format the diff as a git patch, save it as a file, and use git-apply?
Anyone got any good ideas for me?
EDIT: The reason syncing and committing has become unworkable is twofold:
First, the server maintains a list of files you have edited. Syncing with edited files can't be automated easily, so I revert my changes while updating. We have a checkin queue system that only allows you to checkin when nobody in front of you has any of the same files 'on edit' as you. So taking files 'off edit' to update creates a window where it looks like people can safely jump ahead of you.
Second, 开发者_Python百科all branches are stored in the same repository, and we make heavy use of branches. Syncing everything is easy and works, syncing just one directory (that of the branch I'm on) seems buggy. If I sync everything though, the other branches are updated when I don't want them to be. This normally wouldn't be a problem but we have another tool, which makes things... complicated.
- The
apply
command that takes a unified diff and applies it (i.e. there is no "git patch format", it simply unified diff; alsogit apply -
will happily read standard input, so no need to save anything). The
am
command takes an mbox-formatted file with patches and applies and commits each of them. You might be able to easily generate this; it's simply:From au@th.or Mon, 23 May 2011 14:49:12 +0200 From: au@th.or Date: Mon, 23 May 2011 14:49:12 +0200 Subject: First line of commit message Content-length: <bytes-until-next From> Other lines of commit message --- unified diff
concatenated for all the revisions.
- It indeed seems
fast-import
does not accept diffs, but can't you just ask the source system to give you the content of the revision instead (that would handle binary files for which unified diff can't be constructed)? If not, you can askfast-import
to give you the previous content (withcat-blob
command), patch it and feed it in again.
I don't know what your "various reasons this has become unworkable" are, but I have been doing this exact thing at work successfully for quite a while, so I'm familiar with the pitfalls. The trick is to keep your upstream in a separate branch such that you can always do a sync and a git commit
without generating conflicts. I use my master branch for this purpose. My workflow to check in a new feature from a feature branch is something like this:
- git checkout master
- sync to centralized VCS
- git add -A
- git commit -m "Synced from upstream"
- git merge feature
- check in to centralized VCS
- git checkout -b nextfeature
I don't bother getting every single revision from upstream, but you could do that by just doing steps 2-4 for each upstream revision.
精彩评论