git在单个提交文件中恢复单行

时间:2016-07-18 11:22:13

标签: git github

我对git很新,并在github上打开了一个关于项目的拉取请求,该项目包含我在fork中所做的一些更改。 现在,我需要在之前的提交中对单个文件的单行恢复一些更改。

+-------+   +------+   +------+   +------+
|pullreq+<--+commit+<--+commit+<--+commit|
+-------+   +------+   +--+---+   +------+
                          ^
            +-------------+--------------+
            |1  some other peoples code  |
     undo-->+2         my changes        |
            |3  some other peoples code  |
     undo-->+4          my changes       |
            |5          my code          |
            +----------------------------+

什么是最简单的方法来恢复对已经提交的更改的单行进行的更改?

我也试图保留git blame所显示的其他人的修改标记。

//编辑: 我测试了以下内容,它没有保留原始修改标记:
foobar.sh包含其他人提交的行,我添加了新行并更改了现有行,我需要还原对我更改的单行所做的更改。

git clone https://github.com/user/somerepo
cd somerepo
git blame -L 10,20 foobar.sh
nano foobar.sh
git add foobar.sh
git commit
git blame -L 10,20 foobar.sh
nano foobar.sh
git add foobar.sh
git commit
git blame -L 10,20 foobar.sh

1 个答案:

答案 0 :(得分:1)

只需创建一个记录删除这些行的新提交。

您可以在PR分支上推送该提交:它将成为您的请求的一部分。

相关问题