git is almost ubiquitous and its one of the most used tool by developers nowadays, Radically affecting code collaboration.

git has an arsenal of commands, But there are basics like add, status, commit, checkout etc., and there are more powerful commands that require more understanding of git. While working on a Zsh prompt, status got my attention. Because displaying version control information on shell prompt has proven to be useful for me and wanted the indicators in prompt comprehensive as possible, Found some weird behaviour on the way too.

Understanding git status indicators

We’re going to discuss the short-format here. In short format, status of each file is shown as

XY PATH1 -> PATH2

Here, PATHs are relevant only if file is renamed. PATH1 was the old location and PATH2 is the new location of the renamed file. X and Y are the crucial parts here. Before we go into that, Lets have a quick overview about Git itself. Git has three section to handle files — Repository, Index and Work Tree.

Three states of Git (c) Pro Git Book

  • Repository : Where Git stores metadata and object database for the project (The .git directory)
  • Work Tree : Local files that we see and edit.
  • Index : Single binary file that stores information about what goes into the next commit.

X shows the status of the index and Y shows the status of work tree. There are several possible values for X and Y, ?? indicates untracked.

   o   M = modified
   o   A = added
   o   D = deleted
   o   R = renamed
   o   C = copied
   o   U = updated but unmerged

git help status lists many possible combination of these indicators with brief description. You could find a bit elaborated combination of Added, Modified, Deleted and Renamed indicators. There is also regular expressions that can be used to parse and obtain various git values. You might wonder what happened to two other options. U (Updated but unmarked) requires another post dedicated to it and continue reading to know about C indicator.

Git indicator descriptions

Git status copied

How often have you stumbled on the copied indicator ? For me, Its never. Because it’s not intended to be shown with git status, But with git diff [--find-copies] [--find-copies-harder] or with similar options on git log. I was able to emulate copied indicator on git with some help from #git channel on IRC.

There is an unpopular questions on stackoverflow and archive of mailing list discussion regarding this. Still don’t understand why developers thought it might be good idea to add Git status indicator that is not available with git status.