16.1. Listing changed files
The
git status
command shows the current status of your repository and possible actions which you can perform.
It shows which files have changed, which are staged and which are not part of the staging area. It also shows which files have merge conflicts and gives an indication what the user can do with these changes, e.g., add them to the staging area or remove them, etc.
git status -u shows all untracked files. Otherwise, if you have a new directory with severals files, only the directory is shown. |
16.2. Example: Using git status
The following commands create some changes in your Git repository.
Make some changes in your working tree
# assumes that the test01 and test02 files exist
# and have been committed in the past
echo "This is a new change to the file" > test01
echo "and this is another new change" > test02
# create a new file
ls > newfileanalyzis.txt
Now use the status command.
git status
The output of the command looks like the following listing.
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
# (use "git push" to publish your local commits)
#
# 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: test01
# modified: test02
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# newfileanalyzis.txt
no changes added to commit (use "git add" and/or "git commit -a")
16.3. Using git diff
The
git diff
command allows you to compare changes between commits, the staging area and working tree, etc. Via an optional third parameter you can specify a path to filter the displayed changes path can be a file or directory git diff [path]
.
The following example code demonstrate the usage of the
git diff
command.
Make some changes in your working tree
echo "This is a change" > test01
echo "and this is another change" > test02
Use the git diff command
git diff
git diff --cached
git diff COMMMIT_REF1 COMMMIT_REF2
git diff -- [file_reference]
shows the changes introduced in the working tree compared with the staging area | |
shows the differences between the staging area and the last commit | |
shows the differences introduced between two commits references | |
shows the differences introduced in the working tree compared with the staging area for [file_reference] |
0 comments:
Post a Comment