slh*_*hck 182
如果要列出特定分支的所有文件,例如master
:
git ls-tree -r master --name-only
该-r
选项将让它递归到子目录并打印当前受版本控制的每个文件。您还可以指定HEAD
而不是master
获取您可能所在的任何其他分支的列表。
如果您想获取曾经存在的所有文件的列表,请参见此处:
git log --pretty=format: --name-only --diff-filter=A | 排序 -u
Mih*_*otă 81
该git ls-files
命令将执行您需要的操作。
来源:http : //www.kernel.org/pub/software/scm/git/docs/git-ls-files.html
git ls-files
只会打印当前工作目录中的文件。
例如,如果您有一个用于 dotfiles ( core.worktree = /
)的 git repo ,那么您将在 git root 之外拥有文件,并且该简单命令将不再起作用。
简而言之,这将起作用:
git --git-dir "`git rev-parse --git-dir`" \
-C "`git config core.worktree || pwd`" \
ls-files
Run Code Online (Sandbox Code Playgroud)
例子:
mkdir ~/dotfiles
cd ~/dotfiles
git config core.worktree /
# Ignore all files by default, else Git will find all files under "/"
echo "*" > .git/info/exclude
# Add files at the git repo's root and somewhere in the work tree
touch README
git add -f README
git add -f /etc/ssh/sshd_config
# `git status` would now print:
# new file: ../../../etc/ssh/sshd_config
# new file: README
git status
git commit -m "Initial commit"
# At this point, `git ls-files` prints only:
# README
git ls-files
# But you can print all files inside the work tree. This will print:
# etc/ssh/sshd_config
# home/yourusername/dotfiles/README
git --git-dir "`git rev-parse --git-dir`" -C "`git config core.worktree || pwd`" ls-files
Run Code Online (Sandbox Code Playgroud)
如果您希望指定相对于当前(shell)目录的路径,则可以执行以下操作:
alias gls='git ls-tree -r master --name-only HEAD "`git config core.worktree`"'
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,它会打印
README
../../../etc/ssh/sshd_config
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
138384 次 |
最近记录: |