在提交到git之前,如何查看文件中的更改? [英] How can I see what has changed in a file before committing to git?

查看:41
本文介绍了在提交到git之前,如何查看文件中的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到在处理一张或两张票时,如果我走开,我不确定自己在做什么,发生了什么变化等.

I've noticed that while working on one or two tickets, if I step away, I'm not sure what I worked on, what changed, etcetera.

有没有办法在git add然后git commit之前查看给定文件所做的更改?

Is there a way to see the changes made for a given file before git add and then git commit?

推荐答案

您正在寻找

根据您的实际情况,有三种使用 git diff 的有用方法:

Depending on your exact situation, there are three useful ways to use git diff:

  1. 显示索引和工作树之间的差异;也就是说,您尚未准备提交的更改:

git diff [filename]

  1. 显示当前提交和索引之间的差异;也就是说,您将要提交的内容(-staged 会做完全相同的事情,使用您喜欢的内容):
  1. Show differences between current commit and index; that is, what you're about to commit (--staged does exactly the same thing, use what you like):

git diff --cached [filename]

  1. 显示当前提交和工作树之间的区别:

git diff HEAD [filename]

git diff 在目录上递归工作,如果没有给出路径,则显示所有更改.

git diff works recursively on directories, and if no paths are given, it shows all changes.

这篇关于在提交到git之前,如何查看文件中的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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