git 查看当前与上一次version的差异

时间:2022-06-27 08:48:38

http://*.com/questions/9903541/finding-diff-between-current-and-last-versions

As pointed out on a comment by amalloy, if by "current and last versions" you mean the last commit and the commit before that, you could simply use

git show
answered Oct 14 '15 at 17:46
git 查看当前与上一次version的差异
Nighto
1,081921
 
3  
This is what I was looking for. Great answer. – CodeManiak Jan 19 at 22:50
3  
Simpler. This should be the accepted answer. – jbmusso Mar 2 at 9:21
6  
Use git show HEAD~1 to show the last-but-one commit, and git show HEAD~2, etc. for older commits. Show just a single file via git show HEAD~2 my_file. – Florian Brucker Mar 3 at 10:43

Assuming "current version" is the working directory (uncommitted modifications) and "last version" is HEAD (last committed modifications for the current branch), simply do

git diff HEAD

credit for following goes to user Cerran

And if you always skip the staging area with -a when you commit, then you can simply use git diff.

Summary

  1. git diff shows unstaged changes.
  2. git diff --cached shows staged changes.
  3. git diff HEAD shows all changes (both staged and unstaged).

Source: git-diff(1) Manual Page – Cerran

answered Mar 28 '12 at 8:17
git 查看当前与上一次version的差异
CharlesB
43.3k12118141
 
14  
And if you always skip the staging area with -a when you commit, then you can simply use git diff. <1> git diff shows unstaged changes. <2> git diff --cached shows staged changes. <3> git diff HEAD shows all changes (both staged and unstaged). Source: git-diff(1) Manual Page – Cerran Feb 20 '14 at 13:16 
    
This is a good summary. Could be an answer. – user3527975 May 4 at 18:11