如何使用git从其他目录添加文件? [英] How do I add files from another directory with git?

查看:575
本文介绍了如何使用git从其他目录添加文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用浏览器直接在GitHub上创建了一个repo,而不是使用git bash将repo克隆到我的机器上,我可以使用readme文件做bash测试。



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



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



如果你看看第一个链接,我把这个问题放在4个upvotes的答案中,我试图完成他所说的话:这样,你可以分开你的初始源文件夹,从你的Git工作树开始,这就是为什么我试图使用--work-tree = yourSrcFolder add,所以我希望这给了downvoters一些推理的动机。

解决方案

简单地将任何你想添加到repo目录的文件移动到git跟踪中。将一个名为 test.txt 的文件添加到您的git仓库中。


  1. 移动它进入您的版本库目录

  2. 运行 git add test.txt
  3. code> git commit -m将测试文件添加到回购站
  4. 将您的修改推送到远程服务器 git push


I created a repo directly on GitHub using by browser, than using git bash cloned the repo to my machine, I was able to do a test commit with bash using the readme file.

I keep getting fatal: This operation must be run in a work tree when running git --work-tree=yourSrcFolder add .

Was looking here and here for some clue but after 4 hours ready to give up on ever using Git.

If you look at the first link I put in this quesion the answer with 4 upvotes, I was trying to do exactly what he said: "That way, you keep separate your initial source folder, from your Git working tree.", which is why I was trying to use --work-tree=yourSrcFolder add, So I hope that gives the downvoters some reasoning behind my motives.

解决方案

Simply move any file you wish to add into the repo directory, then add them to the git tracking.

Example: suppose you want to add a file named test.txt to your git repo.

  1. Move it into your repository directory
  2. run git add test.txt
  3. commit the file using git commit -m "Added test file to the repo"
  4. push your modification to the remote server git push

这篇关于如何使用git从其他目录添加文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆