3

我在我的 git 历史记录中有一个过去的提交,当时我正在处理功能“X”并意外提交了一个与此功能无关的文件以及其他相关文件。

现在我正在研究功能“Y”,它实际上与之前错误提交的文件有关。

如何以最好的方式处理这种情况?

4

1 回答 1

5

That's how I would have dealt with your problem:

Start an interactive rebase:

git rebase -i COMMIT-OF-FEAT-X^ # notice the ^ at the end

Then change pick to edit for the concerned commit.
You would then be in (please suggest a better wording) that specific commit.

Remove the file from the commit:

git remove --cached wrong_file

That file would then be untracked.

Continue the rebase:

git rebase --continue

You're done.

You can now just switch to the feat-Y branch and add the file, commit it, or do whatever you want with it:

git co feat-Y
git add wrong_file
于 2012-06-24T22:07:27.780 回答