如何将存储库的根目录设置为另一个目录

时间:2016-03-10 21:28:34

标签: github

我对git很新,我真的没有得到这个: 我正在使用教程中列出的命令来添加和提交我的存储库。但我在标题中得到了完整的绝对路径:

HttpSession

我希望该文件夹等同于master。这样文件夹中的所有文件都将直接存储在存储库中。

我做错了什么?

编辑:

澄清一下:我希望计算机上文件夹中的文件直接位于该项目的github页面上,而不是显示在它们显示的子目录中。

screenshot

2 个答案:

答案 0 :(得分:3)

看起来你已经在一个错误的目录中创建了你的git repo(运行$git init)。

如果你问的是如何使你的存储库" flat&#34 ;,即没有子目录,只是根目录中的一堆文件,这就是答案。

假设您在Documents/programming/foo

$ rm -rf ../../../.git # 0
$ git init # 1
$ git remote add origin https://github.com/<your_name>/<your_repo_name> # 2
$ git add -A # 3
$ git commit -m "initial commit 2.0" # 4
$ git push -f origin master # 5

(0) deleting the git metadata from your home directory (trust me, you don't want to make your home directory public on GitHub)
(1) initialize git repo in current working directory (foo)
(2) linking your local repo and the GitHub one by adding a remote
(3) adding all the files to staging area
(4) making a commit
(5) pushing the commit to GitHub

答案 1 :(得分:0)

  

我希望目录中的文件直接位于github页面上,而不是在某个子目录中。

如果您看到Documents/programming/foo,则表示您在主目录中创建了存储库。我想你做过这样的事......

$ cd ~
$ git init

Git存储库包含初始化它的地方以及其下的所有内容。此时,您的存储库将覆盖整个主目录。可能不是你想要的。

在添加文件之前,您的所有文件都不在存储库中。所以你可能做了这样的事......

$ cd Documents
$ mkdir programming
$ cd programming
<edit and save foo>
$ git add foo
$ git commit

现在~/Documents/programming/foo位于存储库中。一旦它被推到Github那就是你会看到的。

相反,您希望为每个项目创建一个Git存储库。因此,请深入查看~/Documents/programming,为项目创建目录,并在其中git init

$ cd ~/Documents/programming
$ mkdir some_project
$ cd some_project
$ git init
<edit and and commit files>
相关问题