git在提交中仅撤消对某些文件的更改

git在提交中仅撤消对某些文件的更改,git,Git,完成此任务的最佳实践是什么: 我已承诺: A -- B -- C 承诺B包括: file1.java file2.java icon.png 我想撤消对文件1和文件2的更改,但不撤消对图标的更改。png您可以恢复提交B,然后在提交之前重置图像文件 # Prepare a revert of B git revert -n B # Recover the current version of the image git checkout HEAD -- icon.png # Commit

完成此任务的最佳实践是什么:

我已承诺:

A -- B -- C
承诺B包括:

file1.java
file2.java
icon.png

我想撤消对
文件1
文件2
的更改,但不撤消对
图标的更改。png

您可以恢复提交B,然后在提交之前重置图像文件

# Prepare a revert of B
git revert -n B

# Recover the current version of the image
git checkout HEAD -- icon.png

# Commit the "almost" reversion of B
git commit

忘记了revert-n添加文件。