如何从远程git存储库一次提交一个提交? [英] How to pull one commit at a time from a remote git repository?

查看:149
本文介绍了如何从远程git存储库一次提交一个提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试图建立一个git仓库的darcs镜像。我有一些工作正常,但有一个重大问题:如果我将一大堆提交到git仓库,这些提交合并到一个darcs补丁集中。我真的想确保每个git commit都被设置为一个darcs补丁集。我敢打赌,通过执行某种 git fetch ,然后询问远程分支的本地副本,可能会有这种可能,但是我的git fu不能胜任这项工作。 p>

下面是我现在使用的(ksh)代码,或多或少:

  git pull -v#从远程提取所有提交---不好! 

#获取只有最后一次提交的信息 - 不好!
author =$(git log HEAD ^ .. HEAD --pretty = format:%an<%ae>)
logfile = $(mktemp)
git log HEAD ^ .. HEAD --pretty =格式:%s%n%b%n> $ logfile

#将所有新文件添加到darcs并记录补丁集。这部分是OK
darcs add -q --umask = 0002 -r。
darcs record -a -A$ author--logfile =$ logfile
darcs push -a $ b $ r rm -f $ logfile



我的想法是


  1. 尝试 git fetch 获取远程分支的本地副本(不确定确切需要哪些参数)
  2. 以某种方式询问本地副本以获得每次提交的散列最后一个镜像操作(我不知道该怎么做)

  3. 循环遍历所有哈希,提取并记录相关的补丁集(我非常确定我知道如何这样做,如果我得到了散列)

我欢迎帮助充实上面的场景 >或有关我应该尝试的其他内容的建议



想法?

解决方案

您是否尝试过寻找一些现有的解决方案来移动版本控制系统之间的变更集,例如裁缝,它说它包含对git和darcs的支持? (这个页面也有类似的系统建议。)

否则,如果你想使用你的建议方法,你可以使用 git在 HEAD origin / master 之后的每个提交上签出来检出在detached HEAD模式。例如,要修改您给出的示例(并且在bourne shell中,恐怕,因为我没有使用ksh):

 #更新所有远程跟踪分支的原始地址
git fetch origin
$ b $ for c in git log --pretty = format:%hHEAD..origin / master`
do
git checkout $ c
author = $(git log -1 --pretty = format:%an<%ae>)
logfile = $(mktemp )
git log -1 --pretty =格式:%s%n%n%b%n> $ logfile

darcs add -q --umask = 0002 -r。
darcs记录-a -A$ author--logfile =$ logfile
darcs push -a
rm -f $ logfile
完成

#现在回到master,并合并以保持master分支是最新的:
git checkout master
git merge origin / master

请注意,这将使git的历史线性化,这本来不是我想要的。 :)我认为最好使用现有的工具来完成这个工作,但上述方法可以起作用。


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

  1. Try git fetch to get local copy of the remote branch (not sure exactly what arguments are needed)
  2. Somehow interrogate the local copy to get a hash for every commit since the last mirroring operation (I have no idea how to do this)
  3. Loop through all the hashes, pulling just that commit and recording the associated patchset (I'm pretty sure I know how to do this if I get my hands on the hash)

I'd welcome either help fleshing out the scenario above or suggestions about something else I should try.

Ideas?

解决方案

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.

这篇关于如何从远程git存储库一次提交一个提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆