下面是一个简短的片段示例(您可以在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
与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
中已经能够执行类似此操作的命令?