使git状态显示未修改/未更改的跟踪文件? [英] Make git status show unmodified/unchanged tracked files?

查看:437
本文介绍了使git状态显示未修改/未更改的跟踪文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是一个简短的片段示例(可以将它粘贴到Linux终端中),创建一个新的 git 存储库并向其添加一些文件(使用git版本1.7。 9.5):

  cd / tmp / 
mkdir myrepo_git
cd myrepo_git /
git init
git config user.nameYour Name
git config user.email you@example.com
echotest> file_tracked_unchanged.txt
echotest> file_tracked_changed.txt
echotest> file_untracked.txt
git add file_tracked_unchanged.txt
git add file_tracked_changed.txt
git commit -m初始提交

现在,在初始提交之后,我想更改 file_tracked_changed.txt 文件,并保留其他文件(这里仅限于 file_tracked_unchanged.txt )在下一次提交时保持不变。下面是一个代码片段,它演示了 git status vs git ls-files git shell输出的前缀为):

  echotest more>> file_tracked_changed.txt 

git status -uno
#在分支主机上
##没有为commit提交的更改:
##(使用git add< file> ; ...更新将提交的内容)
##(使用git checkout - < file> ...放弃工作目录中的更改)
##
##modified:file_tracked_changed.txt
##
#未提交更改(使用git add和/或git commit -a)
git status
# #关于分支主
##没有为commit提交更改:
##(使用git add< file> ...更新将提交的内容)
# git checkout - < file> ...放弃工作目录中的更改)
##
##修改:file_tracked_changed.txt
##
##未追踪文件:
##(使用git add< file> ...包含在将要提交的内容中)
##
##file_untracked.txt
#no更改添加到提交(使用git add和/或git commit -a)
git status -uno --short
#M file_track ed_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
#在分支主机上
##要提交的更改:
##(使用git reset HEAD< file> ... b $ b##
##修改:file_tracked_changed.txt
##
##未列出的未记录文件(使用-u选项显示未记录的文件)
git status
##在分支主机上
##要提交的更改:
##(使用git reset HEAD< file> ...停用)
##
##modified:file_tracked_changed.txt
##
##未记录文件:
##(使用git add< file> ...来包含将要提交的内容)
##
##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

我在寻找的是一个命令,它将显示目录中的所有跟踪文件( git ls-files -v ),它们的准确存储库状态( git ls-files )不显示,因为它显示 H 为所有跟踪文件的状态)。例如,我想获得类似于伪代码的内容:

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

...其中点 U 字符作为这些符号)。



最后,我还想显示目录中所有文件的状态,如伪代码:

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

...但对我来说更重要的是要了解所有跟踪文件的状态,就像上面的伪 git status-tracked 一样。

git 中的任何命令,已经做了这样的事情?

解决方案

谢谢@sdaau。我做了一些更改,以便运行速度更快,并以与 git status 相同的格式提供结果:

  git ls-files |同时读取-r行; 
do
st = $(git status -s$ line);
if [-n$ st];然后
回显$ st;
else
echo$ line;
fi;
完成


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 you@example.com
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?

解决方案

Thanks @sdaau. I've made a few changes so that it runs much faster, and delivers results in the same format as git status:

git ls-files | while read -r line;
do
    st=$(git status -s "$line");
    if [ -n "$st" ]; then
        echo "$st";
    else
        echo "   $line";
    fi;
done

这篇关于使git状态显示未修改/未更改的跟踪文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆