-
Notifications
You must be signed in to change notification settings - Fork 25
History Rewrite
The main KHARMA repository will soon have a history rewrite for a name change. In order to contribute PRs upstream you'll have to synchronize your local repository or GitHub fork. This can be done at any time, but must be done before you can pull new changes from KHARMA upstream.
To test this process, you can use the repository https://github.com/c-prather/kharma, which already has the rewrite applied.
The paranoid (or prudent) may want to back up their entire kharma directory before attempting this, so that they could immediately return to developing on the old history if something fails. We will also be making branch backups with git.
First, fetch updates from the upstream repository:
git fetch --all
then back up your current branch to a new one. e.g. if you are on some branch yourbranch:
git branch backup-yourbranch
or whatever you'd like to call it. Stash any working tree changes:
git stash
and then reset to the updated history of your branch:
git reset --hard origin/yourbranch
Or if AFD did not have a version of your branch, whatever branch of ours you forked from (likely stable). Finally, pop any stashed changes:
git stash pop
If your local branch had new commits vs what was on AFD, you can replay them on top of the new history with git rebase.
First, figure out where your branch diverged from our history -- probably the most recent entry with a branch name in parentheses when you run git log backup-yourbranch. Then make a note of the commit hash, e.g. a1a1a1a. Alternatively, perhaps it is the last with a Prather as commit author.
Then, find the equivalent commit in the new history (git log yourbranch), which will have a different hash, e.g., b1b1b1b, even though it will have the same commit message. You can write the log with git log > log.txt and search through it if you need.
Now we'll be turning each of those commits into its own branch, to be sure we're starting from the same place in the old and new histories:
git checkout a1a1a1a
git checkout -b rewrite-old-base
git checkout b1b1b1b
git checkout -b rewrite-new-base
git checkout backup-yourbranch
git checkout -b new-yourbranch
And the tricky bit: we now use git rebase to take the branch full of your commits (backup-yourbranch), pick out the commits since rewrite-old-base, and replay those commits onto rewrite-new-base instead.
git rebase --onto rewrite-new-base rewrite-old-base new-yourbranch
If all goes well, new-yourbranch will now have the new history followed by all of your commits. While rebases can sometimes be a pain, in this sequence we made sure that the state of the code you're starting from is identical (down to a few comments 😉) so the process should be quite reliable. At worst, you should be able to check out your old branch name and run
git reset --hard backup-yourbranch # DO NOT RUN THIS UNLESS SOMETHING WENT WRONG
which will forcibly restore the state you backed up at the very beginning.
The instructions for a fork look similar to above, but you'll have to pull from the AFD repository for the new history, then push the new history to your fork. Again assuming you have some branch yourbranch checked out which you want to sync:
git remote add afd https://github.com/AFD-Illinois/kharma.git
git fetch --all afd
git branch backup-yourbranch
git stash
git reset --hard afd/yourbranch # or afd/stable or whatever
# If this branch has any of your commits, run the instructions under "If you have local commits"
git stash pop # and commit, if there was anything
git push --all --force
if you want to open more than one pull request, you will have to repeat this for each relevant branch.