Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see what has changed in a file before committing to git?

Tags:

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.

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

like image 877
Satchel Avatar asked Dec 16 '10 01:12

Satchel


People also ask

How do you find the difference before a commit?

The git diff command displays the differences between files in two commits or between a commit and your current repository. You can see what text has been added to, removed from, and changed in a file. By default, the git diff command displays any uncommitted changes to your repository.

How do you see what changes were made in a commit git?

If you have the hash for a commit, you can use the git show command to display the changes for that single commit. The output is identical to each individual commit when using git log -p .


1 Answers

You're looking for

git diff --staged

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

  1. Show differences between index and working tree; that is, changes you haven't staged to commit:
git diff [filename] 
  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. Show differences between current commit and working tree:
git diff HEAD [filename] 

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

like image 97
Cascabel Avatar answered Sep 23 '22 08:09

Cascabel