I'm trying to set up a darcs mirror of a git repository. I have something that works OK, but there's a significant problem: if I push a whole bunch of commits to the git repo, those commits get merged into a single darcs patchset. I really want to make sure each git commit gets set up as a single darcs patchset. I bet this is possible by doing some kind of git fetch
followed by interrogation of the local copy of the remote branch, but my git fu is not up to the job.
Here's the (ksh) code I'm using now, more or less:
git pull -v # pulls all the commits from remote --- bad!
# gets information about only the last commit pulled -- bad!
author="$(git log HEAD^..HEAD --pretty=format:"%an <%ae>")"
logfile=$(mktemp)
git log HEAD^..HEAD --pretty=format:"%s%n%b%n" > $logfile
# add all new files to darcs and record a patchset. this part is OK
darcs add -q --umask=0002 -r .
darcs record -a -A "$author" --logfile="$logfile"
darcs push -a
rm -f $logfile
My idea is
git fetch
to get local copy of the remote branch (not sure exactly what arguments are needed)I'd welcome either help fleshing out the scenario above or suggestions about something else I should try.
Ideas?
The short answer is: you cannot pull a specific commit from a remote. However, you may fetch new data from the remote and then use git-checkout COMMIT_ID to view the code at the COMMIT_ID .
First clone the latest repo from git (if haven't) using git clone <HTTPs link of the project> (or using SSH) then go to the desire branch using git checkout <branch name> . Now the particular commit will be available to your local. Change anything and push the code using git push origin <branch name> . That's all.
The "git clone" command brings down all commits and after cloning you would simply type "git checkout <commit-id>" within the cloned repo to jump around to see different snapshots of the repo from different moments.
Have you tried looking at some existing solutions for moving changesets between version control systems, such as Tailor, which says that it includes support for git and darcs? (There are suggestions for similar systems on that page as well.)
Otherwise, if you want to use your suggested approach, you could use git checkout
on each commit after HEAD
to origin/master
to checkout that commit in "detached HEAD" mode. For example, to modify the example you give (and in bourne shell, I'm afraid, since I don't use ksh):
# Update all remote-tracking branches from origin
git fetch origin
for c in `git log --pretty=format:"%h" HEAD..origin/master`
do
git checkout $c
author=$(git log -1 --pretty=format:"%an <%ae>")
logfile=$(mktemp)
git log -1 --pretty=format:"%s%n%n%b%n" > $logfile
darcs add -q --umask=0002 -r .
darcs record -a -A "$author" --logfile="$logfile"
darcs push -a
rm -f $logfile
done
# Now go back to master, and merge to keep your master branch up to date:
git checkout master
git merge origin/master
Note that this will linearize the history from git, which wouldn't be what I wanted, personally. :) I think it's best to use an existing tool for this, but the above approach could be made to work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With