gpt4 book ai didi

Git Diff - 如何还原选定的行或 block

转载 作者:IT王子 更新时间:2023-10-29 00:56:52 28 4
gpt4 key购买 nike

在 Git GUI 中,我可以选择 diff 的一部分,然后只暂存那些行或 block 。我将如何做相反的事情,如回滚文件中更改的行。通常这些是意外的空白更改,我只想还原但仍暂存/提交同一文件的其他部分。

最佳答案

使用 git add -p 暂存您想要的部分,然后丢弃(git checkout -- filename)未暂存的更改。

Git 1.6.5+ 更新

在版本 1.6.5 中,Git 学会了使用 -p/--patch 标记进行 check out 。您可以使用 git checkout -p -- filename 一步丢弃 block 。

来自 the docs :

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.

关于Git Diff - 如何还原选定的行或 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10826228/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com