gitpatch

Create a git patch between repository and non-repository


I have a situation where a folder needs to be patched to be the same state as a repository. Consider this short tale:

Ten years age Goofus and Gallant are somewhat alike and at a fork in the road Gallant moves onward and becomes a better person. Goofus hangs out and does nothing. The almighty pointy hair decrees Goofus must become more like Gallant again. How can Gallant patch Goofus without making him a clone?

  1. Goofus and Gallant similar but not identical
  2. Gallant enters the repository
  3. Gallant milestone reached
  4. Goofus needs to be patched to Gallant

What's the best way to get the patch?

Should I make a branch and mutate Gallant back to Goofus and then make an inverse patch?


Solution

  • If you want to simply import Goofus back into Gallant (which will be the same as a patch), simply download an archive (zip or tarball) of Goofus, and uncompress it somewhere, then use it as working tree for a one-time import:

    cd /path/to/Gallant
    git --work-tree=/path/to/Unzipped/Goofus add .
    git commit -m "Goofus import"
    git push
    

    The git add part will detect any modified, added or removed files from Goofus, and add them in the Gallant repo.