这是一个简短的片段示例(您可以将其粘贴到您的 Linux 终端中),创建一个新git
存储库并向其中添加一些文件(使用 git 版本 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"
现在,在初始提交之后,我想更改file_tracked_changed.txt
文件,并在下一次提交时保持其他文件(此处仅file_tracked_unchanged.txt
)不变。下面是一个片段,展示了这一点,以及git status
vs的不同输出git ls-files
(git
shell 输出以 为前缀#
):
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
我正在寻找的是一个命令,它将显示目录中的所有跟踪文件(git ls-files -v
确实如此),以及它们准确的存储库状态(git ls-files
不显示,因为它显示H
为所有跟踪文件的状态)。例如,我想获得类似伪代码的东西:
git status-tracked
# M file_tracked_changed.txt
# . file_tracked_unchanged.txt
...其中的点将.
是一个符号,表示已跟踪但未更改的文件(如果我没记错的话,SVN 可能会U
为这些文件使用一个字符)。
最后,我还想显示目录中所有文件的状态,如伪代码所示:
git status-tracked-and-untracked
# M file_tracked_changed.txt
# . file_tracked_unchanged.txt
# ?? file_untracked.txt
...但对我来说更重要的是获得所有跟踪文件的状态,如git status-tracked
上面的伪。
中的任何命令git
,已经做了这样的事情吗?