使用git,如何在不恢复移动的情况下将文本更改恢复到文件?

使用git,如何在不恢复移动的情况下将文本更改恢复到文件?,git,Git,我有一个提交,我移动了文件并更改了文本内容。使用git log--stat-M我看到了这个变化: .../{packages/components/src => src/components}/Card/styles.css | 36 +- 我想还原或修改提交,使其仅包含移动更改。如果要将移动和提交内容更改分开,可以执行以下操作: git branch temp # set a temp branch where we are right now # get the original c

我有一个提交,我移动了文件并更改了文本内容。使用
git log--stat-M
我看到了这个变化:

.../{packages/components/src => src/components}/Card/styles.css | 36 +-

我想还原或修改提交,使其仅包含移动更改。

如果要将移动和提交内容更改分开,可以执行以下操作:

git branch temp # set a temp branch where we are right now
# get the original content into the final location
git show HEAD~1:blah/packages/components/src/Card/styles.css > blah/src/components/Card/styles.css
# create a new revision (amended comment)
git commit --amend -m moving file"
# get the final comment
git checkout temp -- blah/src/components/Card/styles.css
git commit -m "Changed content"
你就完了。现在,如果一切正常,您可以删除临时分支

git branch -D temp

如果要将移动和提交内容更改分开,可以执行以下操作:

git branch temp # set a temp branch where we are right now
# get the original content into the final location
git show HEAD~1:blah/packages/components/src/Card/styles.css > blah/src/components/Card/styles.css
# create a new revision (amended comment)
git commit --amend -m moving file"
# get the final comment
git checkout temp -- blah/src/components/Card/styles.css
git commit -m "Changed content"
你就完了。现在,如果一切正常,您可以删除临时分支

git branch -D temp