What is the short status in Git?

GitLinuxOpen SourceSoftware & Coding

The git status command returns the current state of the −

  • Working area

  • Staging area

This command returns tracked and untracked files and changes made to the repository. However, this command does not show any commit records or information. This command usually returns a status message denoting one of the following states −

  • No commit history

  • Untracked files

  • Changes pending to be committed

  • Clean working tree

  • Modified files

  • Deleted files

The syntax for using the git status command is given below −

$ git status

A screenshot of the above command’s output is below. The output indicates that the file has been modified.

dell@DESKTOP-N961NR5 MINGW64 /e/tut_repo (master)
$ git status
On branch master
Changes not staged for commit:
   (use "git add <file>… " to update what will be committed)
   (use "git restore <file>… " to discard changes in working directory)
      modified: file1.txt

The output shown above is verbose and descriptive. At times we may not want a detailed output. The −−short or −s flag should can be supplied to the git status command to get the output in short format.

The syntax to retrieve status in short format is given below −

$ git status −−short
$ git status −s

The short status of each path is shown as one of the following −

XY PATH
OR
XY ORIG_PATH −>PATH

The status is returned in the second form only if there has been some rename or copy operation. The ORIG_PATH denotes the actual location from where the renamed or copied contents came from. XY is a two−letter status code, where X represents status of the file in the staging area and Y represents status of the file in the working directory. The following table lists the possible values for X and Y.

IndicatorInterpretation
‘ ’Unmodified
MModified
AAdded
DDeleted
RRenamed
CCopied
UUpdated but unmerged

There can be several combinations of the above indicators depending on the status of a file in each of these areas. The status code, ??, represents an untracked file.

Let us understand this with the following examples.

Example 1

  • Create two files “file1.txt” and “file2.txt” and add some content to these files.

$ echo hello >file1.txt
$ echo hello again >file2.txt
  • Use the short status format to view the status −

$ git status −s

The output in the below screenshot (??) indicates that the files are untracked.

aparna. nair@DESKTOP-6EFOVU8 MING64 ~/myrepo (master)
$ git status -s
?? file1.txt
?? file2.txt
  • Let us now add these files to the staging area and verify the status.

$ git add file1.txt
$ git add file2.txt
$ git status -s

The output (A) indicates that the files have been added to the staging area. Note that the indicator A is left aligned and hence, denotes the status of the staging area.

aparna. nair@DESKTOP-6EFOVU8 MING64 ~/myrepo (master)
$ git status -s
A file1.txt
A file2.txt
  • Let us modify the files in the working tree and verify the status.

$ echo new content for file1>>file1.txt
$ echo new content for file2>>file2.txt
$ git status −s

The output (AM) indicates that the content of the file in the staging area and the working tree are different. It means that the file’s content has been modified in the working tree, but the changes to the file are not staged.

aparna. nair@DESKTOP-6EFOVU8 MING64 ~/myrepo (master)
$ git status -s
AM file1.txt
AM file2.txt
  • Let us now commit the changes and observe the status.

$ git add file1.txt
$ git add file2.txt
$ git commit −m ‘changes committed’

A blank output indicates that the working directory is clean.

aparna. nair@DESKTOP−6EFOVU8 MING64 ~/myrepo (master)
$ git status −s
aparna. nair@DESKTOP−6EFOVU8 MING64 ~/myrepo (master)
$

Example 2

  • Create a file “test.txt” and add some content to it. Stage and commit the file to the repository.

$ echo hello >test.txt // create a file with some content
$ git add test.txt // stage the file
$ git commit −m ‘saved to repo’ // commit to the repository
  • Rename the file using Linux mv command and verify the status.

$ mv test.txt test.python
$ git status -s

The output indicates that the “test.txt” file has been deleted from the working tree and the new file “test.python” is untracked.

aparna.nair@DESKTOP-6EFOVUB MINGW64 ~/myrepo (master)
$ git status -s
D test. txt
?? test. python
  • Let us stage these files and verify the status.

$ git add test.txt
$ git add test.python
$ git status -s

The output (R) indicates a rename operation. It denotes that the file is renamed in the staging area from “test.txt” to “test.python”.

aparna. nair@DESKTOP-6EHOVUB MINGW64 ~/myrepo (master)
$ git status − s
R test. txt −> test. python
raja
Published on 20-Feb-2021 09:00:11
Advertisements