我如何从git索引获取文件的内容? [英] How can I get content of a file from git index?

查看:104
本文介绍了我如何从git索引获取文件的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个已经添加到我的本地存储库的文件。我在工作树中修改了它,所以 git status 显示我修改的文件。我想知道在执行文件之前,索引中保存了什么文件内容



我可以想到两种做法那:


  1. 恢复 git diff ,并将其应用到工作树中的文件中
  2. 使用< a href =https://git-scm.com/docs/git-checkout-index =nofollow noreferrer> git checkout-index ,指向一个临时文件并从那里读取内容

是否有更简单的方法?
<使用前缀来访问当前索引中的对象(暂存但尚未提交)。

  git show:file 

有关更多信息,请参阅 gitrevisions手册


I have a file which has been already added to my local repository. I've modified it in the working tree, so git status shows me the file as modified. I would like to know what is the file content kept in the index before I stage the file.

I can think of two ways of doing that:

  1. revert a patch generated by git diff, and apply it on the file in the working tree
  2. use git checkout-index, point to a temporary file and read the content from there

Is there an easier way?

解决方案

Use the : prefix to access objects in the current index (staged but not yet commited).

git show :file

See the gitrevisions manual for more information.

这篇关于我如何从git索引获取文件的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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