git git diff command to view the specific changes Git zone file

 

 

 View Git specific zone file changes git diff

  git status only allows us to know the state of the file changes in the area of Git, but if we want to see specifically what changed within a file (can also be understood as the difference in various regions of Git), this time need to use the git diff command .

  For the b file, because the file is new, it exists only in the work area, and in Untracked state, Git think that the match between the two Git No matter what area did not make sense, the result is no different.

  For a file, because they have been submitted to the warehouse, and in the management of Git, so this file exist in three Git space (work area, staging area, warehouse), we had it in the workspace file changes , whether vs vs warehouses than on the work area or staging area work area, the results should all be a specific file content changes. And if vs warehouse than staging area, and the result should be no difference.


git diff with the view file content changes

View the current file changes (workspace vs staging area) git diff

 

Workspace made changes

// changes after a.txt file can see concrete changes in the file 
[root @ CI-node1 git_test] # echo  " the Test " >> A

Take a look at git stauts, file is modified, the file is git repository management

[root@ci-node1 git_test]# git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   a

no changes added to commit (use "git add" and/or "git commit -a")

Look at the files inside to change what you can not see git status, use git diff

Contrast the work area and staging area

[root@ci-node1 git_test]# git diff a
diff --git a/a b/a
index e69de29..9daeafb 100644
--- a/a
+++ b/a
@@ -0,0 +1 @@
+test

Staging area and a work area to do what changes, plus the test

 

 

// After the changes in a file scratch, to see the changes 
[root @ CI- node1 git_test] # git the Add a 


[root @ CI - node1 git_test] # git Status 
the On Branch Master 
Changes committed to BE: 
  (use " git the RESET the HEAD <File> ... " to unstage) 

    Modified: A 

// compare the work area and the staging area, no change, git diff no output 
[root @ CI-node1 git_test] # git diff A 

// after add workspace and git consistent with the content staging area, contrast,

 

View the current file changes (workspace vs staging area) git diff -cached

This time comparing the staging area and the local repository, you can see specific changes

// compare with the local warehouse staging area, you can see specific changes 
[root @ CI-node1 git_test] # git diff - cached A
 diff - Git A / ab / A 
index e69de29..9daeafb 100644 
--- A / A
 +++ B / A 
@@ - 0 , 0 + . 1 @@
 + Test

At this time the implementation of git commit

[root @ ci-node1 git_test] # Git the commit -m " Modify A " 
[Master af5856a] A Modify 
 . 1  File changed, . 1 Insertion (+ )
 // this time to perform git diff --cached, no output 
[root @ ci git_test -node1] # git diff --cached A

Staging area and as a local warehouse

 

Then be verified

// workspace is clean, three regional work area, staging area, local content repository is consistent 
[root @ CI- node1 git_test] # git Status 
the On Branch Master 
Nothing to the commit, Working Tree Clean

 

After changes to a file, change the workspace, look at change
// After changes a file, changes to the work area, look at the change 
[root @ CI-node1 git_test] # echo  " bbb " > a
 

Now the work area and the staging area is inconsistent, but the staging area and is consistent with local warehouse

// now inconsistent work area and temporary area, but the staging area and the local repository is consistent 
[root @ CI-node1 git_test] # git diff A
 diff - Git A / ab / A 
index 9daeafb..f761ec1 100644 
- - A / A
 +++ B / A 
@@ - . 1 + . 1 @@
 - Test
 + BBB

 

No output, because the staging area and is consistent with local warehouse 
// no output, because the staging area and the local repository is consistent 
[root @ CI-node1 git_test] # git diff --cached A

 

 

 to sum up:

git diff to compare the work area and the staging area

git diff --cached comparison is the staging area and the local warehouse

Guess you like

Origin www.cnblogs.com/mingerlcm/p/11414766.html