- Does a linear commit history exist for any branch head in a git repository, all the way back to an empty git repo? Essentially a list of commits in its history, whose diffs when applied in order can get the empty repo to current state of the branch?
- Is there "git format-patch" command that can extract that linear commit history
- Specifically, that extracted series of patches should should be usable in with a "git init ; git am patches.txt" to reconstruct the latest branch head state, without running into patch conflicts
Even if it means a bit of scripting to achieve what I want above.
----- Question as asked initially --------
I have a git repoA and checked out say branch branchX
I want to generate a sequence of patches with "git format-patch" that i can use to rebuild a brand new git repo using "git am/apply" from scratch(git init) with just that one branchX and its complete history going back to commit zero.
Currently I tried getting the patch as follows from repoA
git --no-pager format-patch --binary --stdout --root branchX > patch.list OR # f7ef86f26066fb428305f3809309ba33d70a9feb is considered the zero/empty state/commit of any git repo git --no-pager format-patch --binary --stdout --root f7ef86f26066fb428305f3809309ba33d70a9feb branchX > patch.list cd /path/to/repoNew git init git am --3way patch.list OR git am patch.list But some how the patch.list generated by above format-patch command
bash-4.2$ git am --3way /witspace/sarvi/space_sarvi_mynxos/kwaiclean/boot/t Applying: Initial branch reference point created applying to an empty history Applying: Admin created refpoint (likely to handle manual repository mucking) Applying: new-module-makes Applying: new-module-makes Applying: new file for sienna target Applying: change the rule for specifying EXTRA_* Applying: Removing Makefile.am files and modifying copyright entry Applying: changes for bringing up isan-image on maui Applying: Adding group 'routing-sw' to /etc/group. The routing-sw components will be started by sysmgr in process group 'routing-sw'. This will allow us to kill/ restart all routing-sw components without rebooting Linux/SANOS. Applying: added a new dhcpd.conf file that is specific to 13-slot Applying: modify the /etc/dhcpd.conf in each lc-line entry to specifiy the slot number as part of creating DHCP links to correct LCImage Applying: Update build infrastructure for DC3 builds Applying: Use our own passwd/group files instead of using the one in basefs Using index info to reconstruct a base tree... M aci/bootglobalpkg/group .git/rebase-apply/patch:34: new blank line at EOF. + warning: 1 line adds whitespace errors. Falling back to patching base and 3-way merge... Auto-merging aci/bootglobalpkg/group Applying: Changes for preparation of new restructure of workspace Applying: DC-OS Codebase Restructure: Stage1 + Stage2 for branch sf Using index info to reconstruct a base tree... M aci/bootbios_program/module.mk Falling back to patching base and 3-way merge... Auto-merging aci/bootbios_program/module.mk CONFLICT (content): Merge conflict in aci/bootbios_program/module.mk error: Failed to merge in the changes. Patch failed at 0015 DC-OS Codebase Restructure: Stage1 + Stage2 for branch sf hint: Use 'git am --show-current-patch=diff' to see the failed patch When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort". bash-4.2$ What I am not getting is if "git format-patch" command, above does get/generates all the commits/patches from initialization of the source/original git repo, in the right order, and the "git am" command only applies them in that same sequence, why would there be conflicts?
How do do this right ?
Why is it not possible to start with a branch head, walk linearly to the first commit and get the sequence of patches in order and apply them in a branch new git repo to reproduce that linear history through patches.
--keep-crto thegit amcommand.