Below commands are used to get
short status about the local git working tree.
git status -s
git status --short
Step 1: Clone the repository ‘https://github.com/harikrishna553/gitHelloWorld.git’.
$git clone https://github.com/harikrishna553/gitHelloWorld.git Cloning into 'gitHelloWorld'... remote: Enumerating objects: 9, done. remote: Counting objects: 100% (9/9), done. remote: Compressing objects: 100% (5/5), done. remote: Total 9 (delta 0), reused 6 (delta 0), pack-reused 0 Unpacking objects: 100% (9/9), done.
Step 2: Navigate to gitHelloWorld folder and execute the command ‘git status
-s’.
$cd gitHelloWorld/ $git status -s $
Since there are no changes done
in local repository, ‘git status -s’ do not print anything.
Step 3: let's add some information to welcome.txt file and execute ‘git status -s’
command.
$git status -s M welcome.txt
‘M’ specifies that the file is
modified.
Step 4: Similarly create new file called ‘hobbies.txt’ and execute ‘git status
-s’ command.
$git status -s M welcome.txt ?? hobbies.txt
?? represents that this file is
untracked.
Step 5: let's add hobbies.txt to index and execute ‘git status -s’ command.
$git add hobbies.txt $ $git status -s A hobbies.txt M welcome.txt
‘A’ represents that new file is
added to staging area.
As you see the output of ‘git
status -s’ command, every row in the output is divided into 3 columns. First
column represents staging area, second column represents Modified area and third
column represent file name.
Let’s add welcome.txt to
staging and execute ‘git status -s’ command.
$git add welcome.txt $ $git status -s A hobbies.txt M welcome.txt
M welcome.txt
Above statement specifies that
welcome.txt file is modified and added to staging area.
Step 7: let's update welcome.txt again by updating some content in it.
$git status -s A hobbies.txt MM welcome.txt
MM welcome.txt
From the above statement it is
clear the welcome.txt file is updated and it is in both staging area and
modified area.
‘git status’ output is given
below.
$git status On branch master Your branch is up to date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: hobbies.txt modified: welcome.txt 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: welcome.txt
How can a file be in
both modified and staging area?
When you first moved
'welcome.txt' file from modified state to staging using 'git add' command, the
changes in the file 'welcome.txt' at that point are added to staging area. When
you re update the file 'welcome.txt' after staging, then git sees it as new
change and place it in modified area. If you commit the files in staging area
right now, then staged files will get committed, but not the latest update of
'welcome.txt' file.
$git status -s A hobbies.txt MM welcome.txt $ $git commit -m "Adding hobbies and welcome files" [master 306439d] Adding hobbies and welcome files 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 hobbies.txt $ $git status -s M welcome.txt $ $git status 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: welcome.txt no changes added to commit (use "git add" and/or "git commit -a")
No comments:
Post a Comment