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.

4

1 回答 1

1

一种可能性是创建第二个分支,将第一个分支重置为有问题的提交之前,然后从第二个分支中挑选所需的提交。

git checkout branch1
git checkout -b branch2
git reset --hard <commit sha>
git cherry-pick <commit sha from branch 2>
...
于 2015-01-23T18:02:04.993 回答