如何使用git从其他目录添加文件?

Out*_*uch 1 git github

我使用浏览器直接在GitHub上创建了一个repo,而不是使用git bash将repo克隆到我的机器上,我能够使用自述文件对bash进行测试提交.

我一直致命:运行git -work-tree = yourSrcFolder add时,必须在工作树中运行此操作.

这里这里寻找一些线索,但在4小时后准备放弃使用Git.

如果你看看我在这个问题中提出的第一个链接4个upvotes的答案,我试图完全按照他说的那样做:"那样,你将你的初始源文件夹与你的Git工作树分开.",这是为什么我试图使用--work-tree = yourSrcFolder add,所以我希望这会让downvoters在我的动机背后有一些推理.

And*_*mov 12

我的解决方案是创建放置在另一个目录中的文件的硬链接.

您可以使用ln命令(mklink在Windows上)来实现此目的(假设您当前位于存储库目录中):

# this will add file with the same name to current directory and same inode
ln ../../filename . 
Run Code Online (Sandbox Code Playgroud)

然后将它添加到git索引:

git add filename
Run Code Online (Sandbox Code Playgroud)

如果您需要,请提交:

git commit -m "add file from another directory"
Run Code Online (Sandbox Code Playgroud)

inode,ln.