Pra*_*eep 146 git version-control git-svn
在我跟踪svn repo的git repo中,我对一个文件进行了大量编辑.
现在我想恢复这些更改(如svn revert),但只是部分文件.
我希望能够查看文件中的差异,丢弃(还原)我不想要的更改并保留我想要的更改.
该
git add -i
Run Code Online (Sandbox Code Playgroud)
命令似乎有一个选项可以做到这一点,但我不想暂时这样做.
Dan*_*ach 305
我相信你可以做到最简单:
git checkout -p <optional filename(s)>
Run Code Online (Sandbox Code Playgroud)
从联机帮助页:
Run Code Online (Sandbox Code Playgroud)?p, ??patch Interactively select hunks in the difference between the <tree?ish> (or the index, if unspecified) and the working tree. The chosen hunks are then applied in reverse to the working tree (and if a <tree?ish> was specified, the index).
This means that you can use git checkout ?p to selectively discard
edits from your current working tree.
Run Code Online (Sandbox Code Playgroud)
Pao*_*tti 90
你可以直接用它来做git checkout -p.请参阅下面的Daniel Stutzbach的回答.
旧答案(之前checkout -p介绍):
你可以这样做:
git add -i
Run Code Online (Sandbox Code Playgroud)
(选择你想要保留的帅哥)
git commit -m "tmp"
Run Code Online (Sandbox Code Playgroud)
现在您只提交了要保留的更改,其余的都是未提交的.
git reset --hard HEAD
Run Code Online (Sandbox Code Playgroud)
此时,未提交的更改已被丢弃,因此您有一个干净的工作目录,并且您希望将更改保留在最前面.
git reset --mixed HEAD^
Run Code Online (Sandbox Code Playgroud)
这将删除最后一次提交('tmp'),但会将修改保留在您的工作目录中,而不是已暂存.
编辑:替换--soft为--mixed,以清理临时区域.
| 归档时间: |
|
| 查看次数: |
32147 次 |
| 最近记录: |