【问题标题】:Creating a README.md in GitLab在 GitLab 中创建 README.md
【发布时间】:2022-01-16 18:28:09
【问题描述】:

我在 GitLab(在浏览器中)创建了一个新的空白项目。我选中了“使用 README 初始化存储库”框。但是打开它时,它说:“这个项目的存储库是空的。”我假设我仍然需要初始化一个 README.md 文件以便主分支存在?所以在我尝试的命令行中(我使用的是Windows 10):

git clone https://gitlab.com/url/myproject.git
cd myproject
git switch -c main
touch README.md
git add README.md
git commit -m "add README"

但它说:

C:\Users\me>git clone https://gitlab.com/ur/myproject.git
fatal: destination path 'myproject' already exists and is not an empty directory.

C:\Users\me>cd myproject

C:\Users\me\myproject>git switch -c main
fatal: A branch named 'main' already exists.

C:\Users\me\myproject>touch README.md
'touch' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\me\myproject>git add README.md

C:\Users\me\myproject>git commit -m "add README"

On branch main
Your branch is based on 'origin/main', but the upstream is gone.
  (use "git branch --unset-upstream" to fixup)

nothing to commit, working tree clean

我的项目仍然是空的,我无法添加或推送任何内容。为什么?

编辑:如果我导航到项目并执行dir,我会得到(我只删除了卷序列号):

C:\Users\me\myproject>dir
 Volume in drive C has no label.
 Volume Serial Number is ...

 Directory of C:\Users\me\myproject

13.12.2021  09:29    <DIR>          .
13.12.2021  09:29    <DIR>          ..
13.12.2021  09:29                 0 README.md
               1 File(s)              0 bytes
               2 Dir(s)  112.515.997.696 bytes free

【问题讨论】:

  • 这很可能会演变成很多 cmets。首先touch 是*nix 命令,因此在Windows 上不存在。在你的编辑器中创建一个 README.md 文件并保存它会起作用。尝试删除您的 myproject 目录,然后再次克隆并执行 dir 以查看您有哪些文件。
  • @doctorlove 我导航到该项目并在原始帖子中发布了我得到的内容。我无法从浏览器创建 README.md,因为我没有那个按钮。但是如果我去我的电脑文件夹里,有一个README.md文件……
  • @doctorlove 如果我从计算机中删除该文件夹并再次克隆它,它会说我克隆了一个空仓库。

标签: git gitlab commit readme


【解决方案1】:

让我们一一分解错误。

C:\Users\me>git clone https://gitlab.com/ur/myproject.git
fatal: destination path 'myproject' already exists and is not an empty directory.

myproject 文件夹已经存在 - 很可能您已经克隆了项目,所以这里没有更多的事情要做。

C:\Users\me\myproject>git switch -c main
fatal: A branch named 'main' already exists.

您无法创建 main 分支,因为它已经存在 - 再说一遍,这里无事可做。

C:\Users\me\myproject>touch README.md
'touch' is not recognized as an internal or external command,
operable program or batch file.

touch 是 Windows 中不存在的 *nix 命令。一种选择是使用 Git Bash 而不是 CMD,它提供了一个 touch 可执行文件。或者,您可以使用another method to create an empty file in Windows

C:\Users\me\myproject>git add README.md

C:\Users\me\myproject>git commit -m "add README"

On branch main
Your branch is based on 'origin/main', but the upstream is gone.
  (use "git branch --unset-upstream" to fixup)

nothing to commit, working tree clean

这两个命令没有失败,它们什么也没做,因为README.md 文件没有创建。创建完成后,您可以重复这两个命令,它们应该会成功。

【讨论】:

  • 我现在删除了我电脑中的目录,再次克隆它,导航到它,切换到一个新的分支“main”,但现在最后两个命令失败了,就像你说的那样。愚蠢的问题,但我如何创建README.md 文件? Web 界面中没有选项,我想我可以使用 git add 来完成。
  • 好的,我使用了 bash 并添加了它,它在我电脑上的文件夹中。但它仍然不在网络浏览器上。
  • git add 只是暂存一个要提交的文件,它不会创建它-您必须以操作系统的某种本机方式执行此操作(例如,请参阅我共享的链接) . WRT“网络界面中没有选项” - 我想我在这里失去了你。你指的是什么网页界面?
  • 我想说的是,尽管遵循命令并提交(我在 bash 中完成了所有操作),并且 README.md 文件出现在我系统的文件夹中,如果我去网络该项目的页面,它仍然显示“该项目的存储库是空的”。
  • @futuredataengineer 听起来像是权限问题 - 请参阅 stackoverflow.com/q/52026119/2422776
猜你喜欢
  • 2017-09-30
  • 1970-01-01
  • 2022-01-16
  • 2016-10-06
  • 2019-09-27
  • 1970-01-01
  • 2015-06-13
  • 2018-04-19
  • 2017-09-03
相关资源
最近更新 更多