0

I was pair programming on a project with a colleague. We made great progress but we forgot to commit the work we collaborated on. Later on, my team mate went off and made some experimental changes in another part of the code base. He then committed that experimental work, and accidentally included the work we did together without realizing it.

I now have a fork of his branch and the commit with our combined work. Is there a way to go through each line of code that was add/removed in that commit and choose to keep or revert it?

chopper draw lion4
  • 12,401
  • 13
  • 53
  • 100
  • 1
    Possible duplicate of [Reverting part of a commit with git](http://stackoverflow.com/questions/4795600/reverting-part-of-a-commit-with-git) – Jack Gore Mar 31 '17 at 17:44

1 Answers1

0

well it's never wise to edit git's history but if you MUST you can always use git rebase. read carefully the man page associated to it. i suppose what you need to do is something among these line:

git rebase -i <commit>

this will launch an interactive editor with the list of commits in that revision, there the first column of each commit listed indicates what action should be performed with given commit; one of those actions is edit. when an edit is found git rebase stops so that you can edit the files or the commit message, amend the commit and then continue rebasing.

i recommend reading carefully man git rebase and try first the dynamics of the command in a test repo.

odradek
  • 993
  • 7
  • 14