gpt4 book ai didi

git - 如何在不更改当前工作目录的情况下 git 添加文件?

转载 作者:太空狗 更新时间:2023-10-29 13:17:26 26 4
gpt4 key购买 nike

我想在不更改当前工作目录的情况下在 git 中添加和提交文件。这可能吗?

> pwd
/tmp

> git --git-dir=/tmp/git_test/.git init
Initialized empty Git repository in /tmp/git_test/.git/

> ls /tmp/git_test
commit1

> git --git-dir=/tmp/git_test/.git add /tmp/git_test/commit1
fatal: '/tmp/git_test/commit1' is outside repository

> git --git-dir=/tmp/git_test/.git add commit1
fatal: pathspec 'commit1' did not match any files

(git add -A 似乎使用当前工作目录,而不是 --git-dir 的参数)

最佳答案

您错过了一个选项:--work-tree .如果您在存储库之外,则需要同时提供它和 --git-dir :

--work-tree=<path>

Set the path to the working tree. It can be an absolute path or a path relative to the current working directory. This can also be controlled by setting the GIT_WORK_TREE environment variable and the core.worktree configuration variable (see core.worktree in git-config(1) for a more detailed discussion).

关于git - 如何在不更改当前工作目录的情况下 git 添加文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9797387/

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