Import changes into a git repository from universal diff

北慕城南 提交于 2019-12-05 18:54:15

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:

  1. git checkout master
  2. sync to centralized VCS
  3. git add -A
  4. git commit -m "Synced from upstream"
  5. git merge feature
  6. check in to centralized VCS
  7. 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.

  • The apply command that takes a unified diff and applies it (i.e. there is no "git patch format", it simply unified diff; also git 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 ask fast-import to give you the previous content (with cat-blob command), patch it and feed it in again.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!