Quantcast
Channel: Jonathan Channon's Blog » Uncategorized
Viewing all articles
Browse latest Browse all 16

Modifying files within Git history

$
0
0

If you have been doing code changes and committing as you go and then look back at the changes you may see something you don’t like the look of. Assuming no-one has a copy of your code changes you can go back and modify the files at a certain point in time within your commit history.

I use Git Bash by default but the editor sucks compared to Sublime Text so first things first lets setup the Git editor.

For Sublime Text run this in the command line:

1
git config --global core.editor "'C:/Program Files/Sublime Text 2/sublime_text.exe'"

Next up is finding the commit id you want to go back to, to edit:

1
git log

Make a note of the parent commit id of the commit you want to edit.

Run this:

1
git rebase --interactive 1185cb0de5d5e5b4c79f83a0c51ed06a5d22d7c4^

This will open Sublime Text and you’ll see lines similar to:

1
2
pick d3adb33 My Commit message
pick d5bdb67 Other Commit message

Change “pick” to “edit” on the commit you want to modify, save and exit

You can then make the changes to your files and when ready run:

1
git commit --all --amend

Sublime Text will open again so you can edit the commit message, just save, exit and run:

1
git rebase --continue

We’re done!

Your previous commit has been amended and you’re back to where you were with the latest commits ready to be pushed.


Viewing all articles
Browse latest Browse all 16

Latest Images

Trending Articles





Latest Images