pba-content icon indicating copy to clipboard operation
pba-content copied to clipboard

Define flow for applying patches with divergent git histories

Open nuke-web3 opened this issue 2 years ago • 5 comments
trafficstars

We on occasion need to issue a patch to a classroom assignment, but sadly each new template repo derived for every student has a random init commit hash, and thus git apply workflows do not work. (related to #357 )

patch : (man page) seems to be the tooling we need to get around this: see this post & a little demo.

  • [ ] Define a diff & patch with divergent git history workflow in a how-to for instructors
  • [ ] Template message to send out to those needing to apply the patch (this can include the actual body of the patch! or as an attachment)
  • [ ] Reference this new guide in exercises & assignments and the https://github.com/Polkadot-Blockchain-Academy/Rust-Entrance-Exam where this pattern is important.

nuke-web3 avatar May 04 '23 17:05 nuke-web3

I just had a mind blow moment. I learned about git merge --allow-unrelated-histories. This might be the thing that finally stops me bitching about github classroom not preserving history.

JoshOrndorff avatar Jul 06 '23 15:07 JoshOrndorff

--allow-unrelated-histories. turned out to be a red herring.

Rather, patch is nice!

# instructor with changes on some branch (could be commits diff too)
git diff main fixes-branch > assignment-X-patch.diff

# Send diff file to students

# students run
patch -p1 < assignment-X-patch.diff

# students review file changes, stage, and commit

Assumes students have same file structure and maybe close-sh line numbers. If this patch is not working, try making a diff with more lines of context

# 100 lines of context around lines changed
git diff -U100 branch1 branch2 > assignment-X-patch.diff

nuke-web3 avatar Jul 21 '23 12:07 nuke-web3

damn. Many could not do this patch, with anything added to the original file. Some one gymnastics are needed

https://git-scm.com/docs/git-apply might be a better option. :shrug: will try more things latter on

nuke-web3 avatar Jul 21 '23 23:07 nuke-web3

--allow-unrelated-histories. turned out to be a red herring.

What made you conclude this?

JoshOrndorff avatar Jul 23 '23 17:07 JoshOrndorff

Any variation of this I tried was more than a one liner like patch (I thought) was, and every one was a full file diff there was only all or nothing for and changes at all.

nuke-web3 avatar Jul 24 '23 00:07 nuke-web3