gpt4 book ai didi

git - git 的版本库根路径的语法是什么?

转载 作者:太空狗 更新时间:2023-10-29 12:46:10 24 4
gpt4 key购买 nike

当使用 git add -u 时,我可以提供一个路径作为最后一个参数,例如git add -u .。如何提供存储库根路径?

我想用它来快速将对跟踪文件的所有更改添加到索引中,包括对目录树更上层文件的更改。

示例

$ git status# On branch mul# Changes not staged for commit:#   (use "git add ..." to update what will be committed)#   (use "git checkout -- ..." to discard changes in working directory)##       modified:   ../../../foo.mwb#no changes added to commit (use "git add" and/or "git commit -a")

最佳答案

冒号:在这里有帮助,您可以通过 :/ 引用存储库的根目录:

git init test
cd test
mkdir a
touch a/a
git add a
git commit -m a
# Here comes the interesting part:
cd a
touch ../root
git add :/
git commit -m root

上面的脚本初始化了一个玩具存储库,其中包含一个文件 a在子目录中 a .在“有趣的部分”中,它变为 a目录,在存储库的根目录中创建一个空文件并使用 :/ 添加它引用。 -u开关照常工作(未在脚本中显示)。

manual of git-rev-parse 阅读:

<rev>:<path>, e.g. HEAD:README, :README, master:./README

A suffix : followed by a path names the blob or tree at the given path in the tree-ish object named by the part before the colon. :path (with an empty part before the colon) is a special case of the syntax described next: content recorded in the index at the given path. A path starting with ./ or ../ is relative to the current working directory. The given path will be converted to be relative to the working tree’s root directory. This is most useful to address a blob or tree from a commit or tree that has the same tree structure as the working tree.

不幸的是,bash自动完成功能不适用于 :/构造。

related question询问查找存储库的绝对路径;当然你也可以做git add $(git rev-parse --show-toplevel)top-voted answer 中所述.

关于git - git 的版本库根路径的语法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17214368/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com