Git:在不碰触工作树的情况下展示某些文件内容的能力 [英] Git: ability to stage a certain file content without touching the working tree

查看:94
本文介绍了Git:在不碰触工作树的情况下展示某些文件内容的能力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想修改一个(文本)文件的索引而不必更改工作树文件状态。这是可能的吗?

I want to modify the index of one (text) file without having to change the working tree file state. Is this possible?

推荐答案

另外,在不改变工作目录的情况下更改索引中的文件是将补丁应用于仅索引。这通常是GUI git客户端仅从给定文件中选择行的方式。

Another take on "changing file in index without altering working dir" is to apply a patch to index only. This is often the way GUI git clients stage only selected lines from a given file.

您从(如果需要的话)开始清除该文件的索引更改:

You start out by (if you want) clearing out the changes from index for that file:

git reset path/to/file

然后为它提取完整的补丁

Then extracting the full patch for it

git diff path/to/file > /path/to/tmpfile

编辑修补程序文件以仅包含要应用的更改,只应用编辑过的补丁:

Edit the patch file to include only the changes you want to apply, and apply just the edited patch:

git apply --cached /path/to/tmpfile

请参阅:

See:

git help apply

这篇关于Git:在不碰触工作树的情况下展示某些文件内容的能力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆