4 ms·
The one thing I'd like to do is to insert a commit between two commits, then edit this and then make a modification. Currently I create a text file, add this,
by chris_wot 4y ago
The one thing I'd like to do is to insert a commit between two commits, then edit this and then make a modification.
Currently I create a text file, add this, then move this up to where I need to insert it and edit this commit.
- throwaway_au_1 4y agoIt's not clear to me exactly what you mean. Based on adding the text file, which sounds like you're creating a placeholder commit, you might not know about 'git commit --allow-empty' which may serve you better. Not exactly sure of your order of events wrt inserting a commit and editing it (I.e. edit commit message? Or changes?) and modifying it (I.e. see previous) but am happy to try and help if you want to flesh out your example a little more.
- throwaway_au_1 4y agoTo speculate, maybe you haven't heard of fixup/squash. E.g. Commit 1 Commit 2 Commit 3 Using an empty fixup commit, e.g. git commit --allow-empty --fixup=commit2hash You would end up with Commit 1 Commit 2 Commit 3 fixup! Commit 2 Which will adjust automatically (when starting interactive rebase with autosquash) to Commit 1 Commit 2 fixup! Commit 2 Commit 3 You could then simply change the rebase 'fixup' instruction to 'reword' to edit/remove the 'fixup!' part of the message, or 'edit' to continue the rebase uo until that commit and then stop. That said, again, not clear on your use case but maybe that might help you or another reader.
- alisonatwork 4y agoYou can also just `git rebase -i` and set `e` (edit) on the commit before the one where you want to insert a new commit. Instead of doing `git add .` and `git rebase --continue` like you normally would to squash your changes into the commit you've stopped to edit, you can just `git add .`, `git commit -mwhatever` and then `git rebase --continue`. Now you have new commit "whatever" in between the one you stopped to edit on and the next one.