So I’m currently making a site with HTML5 and and I’m quite a ways in when I realize that I forgot to put in the HTML5 resets in to my css file.
Currently I’m about 10 commits in and what I would like to do is to add the reset code in to the css file into my very first commit and have it present in the rest of the commits after.
I read around a bit and I think git rebase is the way to go but Im not really sure how to use it correctly.
This SO question seems to be close to what I want to do, but Im not well versed in Git yet to adapt this.
Thanks in advance.
Try this:
1) Check out the past commit you want to change with
git checkout.2) Tag this past commit using
git tag PastCommit.3) Use
git checkout -b FixBranchto create a new branch called FixBranch.4) Add the new file in and make a new commit on FixBranch.
5) Switch to your master branch using
git checkout master.6) Tag using
git tag BACKUPin case you screw something up – just to be safe before a rebase 🙂7) Use
git rebase --onto FixBranch PastCommit– this will rebase the stuff between PastCommit and the head of master onto FixBranch.8) Tidy up using
git tag -d PastCommit,git tag -d BACKUPandgit branch -d FixBranch.9) Use
git gcto garbage collect and get rid of any dangling commits.Note that you can (and should!) visualise all this in
gitkso that you can see what you’re doing (and make sure I haven’t missed anything – this is a bit off the top of my head).Addendum: I just tried this on a test repository and it works fine.