Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show uncommitted changes in Git and some Git diffs in detail

Tags:

git

git-diff

How do I show uncommitted changes in Git?

I STFW'ed, and these commands are not working:

teyan@TEYAN-THINK MINGW64 /d/nano/repos/PSTools/psservice (teyan/psservice) $ git status On branch teyan/psservice Your branch is up-to-date with 'origin/teyan/psservice'. Changes to be committed:   (use "git reset HEAD <file>..." to unstage)          modified:   psservice.c         modified:   psservice.vcxproj.filters   teyan@TEYAN-THINK MINGW64 /d/nano/repos/PSTools/psservice (teyan/psservice) $ git diff  teyan@TEYAN-THINK MINGW64 /d/nano/repos/PSTools/psservice (teyan/psservice) $ git diff master fatal: ambiguous argument 'master': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]' 
like image 863
TD_Yan Avatar asked Mar 14 '16 02:03

TD_Yan


People also ask

How do I see changes in git diff?

You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch. Order does matter when you're comparing branches.

Why git diff does not show changes?

Your file is already staged to be committed. You can show it's diff using the --cached option of git. To unstage it, just do what git status suggests in it's output ;) You can check The Git Index For more info.

Which command shows the changes between commits git diff?

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.


1 Answers

How to show uncommitted changes in Git

The command you are looking for is git diff.

git diff - Show changes between commits, commit and working tree, etc


Here are some of the options it expose which you can use

git diff (no parameters)
Print out differences between your working directory and the index.

git diff --cached:
Print out differences between the index and HEAD (current commit).

git diff HEAD:
Print out differences between your working directory and the HEAD.

git diff --name-only
Show only names of changed files.

git diff --name-status
Show only names and status of changed files.

git diff --color-words
Word by word diff instead of line by line.

Here is a sample of the output for git diff --color-words:

enter image description here


enter image description here

like image 62
CodeWizard Avatar answered Oct 18 '22 14:10

CodeWizard