0

In a project a subcontractor moved some files around in the tree, did a commit (Git marked them as deleted), used git add to re-add them to the tree. That happened several commits ago. Before I merge the changes back into my tree, I'd like to fix this. How can I "reconnect" these files at the right place in the git history?

Update

Okay, so, because people are suggesting a commit undo. That's not what I want (I think).

Imagine the following situation

A
|
|\
| \
|  B
|   mv file_x file_y
|   git commit 1
|   |
|   |
|   git commit 2
|   |
|   |
|   git commit 3
|   |
|   |
|   git add file_y
|   git commit 4
| /
|/
|

I'd like to "splice" the history of file_x up to commit 1 with file_y since commit 4 without loosing any of the other changes that happened in between and commits 1 and 4.

Community
  • 1
  • 1
datenwolf
  • 155,162
  • 12
  • 177
  • 284
  • If the commit contains only that action, you should be able to simply revert the commit, no? – isherwood Jan 23 '15 at 17:28
  • @isherwood, a `git revert` would create a new commit at the currently active head. I think the OP wants the changes to be undone at the same point where they were originally made. – Chris Jan 23 '15 at 17:45
  • 1
    possible duplicate of [Undo a particular commit in Git](http://stackoverflow.com/questions/2318777/undo-a-particular-commit-in-git) – isherwood Jan 23 '15 at 17:52
  • See the answer by naomik. – isherwood Jan 23 '15 at 17:55
  • It's not a simple "undo" I want to make. Essentially I'd like to "splice" the file history between the delete and the add. – datenwolf Jan 23 '15 at 17:55

1 Answers1

1

One possibility would be to create a second branch, reset the first branch to prior to the offending commit, then cherry-pick the desirable commits from the second branch.

git checkout branch1
git checkout -b branch2
git reset --hard <commit sha>
git cherry-pick <commit sha from branch 2>
...
isherwood
  • 52,576
  • 15
  • 105
  • 143