Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make git status show unmodified/unchanged tracked files?

Tags:

Here is a brief snippet example (which you can paste in your Linux terminal), creating a new git repository and adding some files to it (using git version 1.7.9.5):

cd /tmp/
mkdir myrepo_git
cd myrepo_git/
git init
git config user.name "Your Name"
git config user.email [email protected]
echo "test" > file_tracked_unchanged.txt
echo "test" > file_tracked_changed.txt
echo "test" > file_untracked.txt
git add file_tracked_unchanged.txt 
git add file_tracked_changed.txt
git commit -m "initial commit"

Now, after the initial commit, I want to change the file_tracked_changed.txt files, and keep the others (here, only file_tracked_unchanged.txt) unchanged for the next commit. Below is a snippet which demonstrates that, and the diverse outputs of git status vs git ls-files (git shell output is prefixed with #):

echo "test more" >> file_tracked_changed.txt

git status -uno
# # 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:   file_tracked_changed.txt
# #
# no changes added to commit (use "git add" and/or "git commit -a")
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:   file_tracked_changed.txt
# #
# # Untracked files:
# #   (use "git add <file>..." to include in what will be committed)
# #
# # file_untracked.txt
# no changes added to commit (use "git add" and/or "git commit -a")
git status -uno --short
#  M file_tracked_changed.txt
git status --short
#  M file_tracked_changed.txt
# ?? file_untracked.txt
git ls-files -v
# H file_tracked_changed.txt
# H file_tracked_unchanged.txt

git add file_tracked_changed.txt

git status -uno
# # On branch master
# # Changes to be committed:
# #   (use "git reset HEAD <file>..." to unstage)
# #
# # modified:   file_tracked_changed.txt
# #
# # Untracked files not listed (use -u option to show untracked files)
git status
# # On branch master
# # Changes to be committed:
# #   (use "git reset HEAD <file>..." to unstage)
# #
# # modified:   file_tracked_changed.txt
# #
# # Untracked files:
# #   (use "git add <file>..." to include in what will be committed)
# #
# # file_untracked.txt
git status -uno --short
# M  file_tracked_changed.txt
git status --short
# M  file_tracked_changed.txt
# ?? file_untracked.txt
git ls-files -v
# H file_tracked_changed.txt
# H file_tracked_unchanged.txt

What I'm looking for, is a command which will show all tracked files in a directory (which git ls-files -v does), with their accurate repository status (which git ls-files doesn't show, as it shows H as status for all tracked files). For instance, I'd like to obtain something like the pseudocode:

git status-tracked
# M file_tracked_changed.txt
# . file_tracked_unchanged.txt

... where the dot . would a symbol indicating a tracked, but unchanged file (if I recall correctly, SVN may use a U character for these).

Ultimately, I'd like to also show the status of all files in a directory, as in the pseudocode:

git status-tracked-and-untracked
# M file_tracked_changed.txt
# . file_tracked_unchanged.txt
# ?? file_untracked.txt

... but it's more important to me to get to the status of all tracked files, as in the pseudo git status-tracked above.

Any command in git, that already does something like this?

like image 956
sdaau Avatar asked Apr 30 '13 19:04

sdaau


People also ask

How do you git add all modified files but not untracked?

The easiest way to add all files to your Git repository is to use the “git add” command followed by the “-A” option for “all”. In this case, the new (or untracked), deleted and modified files will be added to your Git staging area. We also say that they will be staged.

Which command is used to see which changes are not currently tracked by git?

The git status command displays the state of the working directory and the staging area. It lets you see which changes have been staged, which haven't, and which files aren't being tracked by Git.

How do I show tracked files in git?

This command will list the files that are being tracked currently. If you want a list of files that ever existed use: git log --pretty=format: --name-only --diff-filter=A | sort - | sed '/^$/d'This command will list all the files including deleted files.


1 Answers

Quick one-liner that works on Linux:

sort -uk 2bi <(git status -s) <(git ls-files | sed 's/^/ . /')

like image 192
hashstat Avatar answered Oct 10 '22 20:10

hashstat