将第一次提交存储在空项目仓库中

时间:2016-03-14 10:03:05

标签: git

我是git的新手,并尝试了解我将如何撤消/存储更改+日志让我说我有一个非常新的分支,但没有提交,例如

git clone https://url   testrepo
cd testrepo
git log 

   fatal: bad default revision 'HEAD'

git checkout

   fatal: You are on a branch yet to be born

echo "test" > README.txt
git status

On branch master
Initial commit

Untracked files:   (use "git add <file>..." to include in what will be
committed)

    README.txt

nothing added to commit but untracked files present (use "git add" to track)

git add .
git status 

On branch master

Initial commit

Changes to be committed:   (use "git rm --cached <file>..." to unstage)
    new file:   README.txt
git commit -m "My read me file "

[master (root-commit) 6357fd2] My read me file
1 file changed, 1 insertion(+)
create mode 100644 README.txt

git status

On branch master Your branch is based on 'origin/master', but the        
upstream is gone.   (use "git branch --unset-upstream" to fixup)
nothing to commit, working directory clean

(我不明白“上游消失了”是什么意思:()

但是,现在让我们说要隐藏所有更改。一个简单的解决方案是删除克隆并从远程仓库重新克隆。有什么其他选项来撤消上面的提交,所以我将再次进行干净的结账(没有提交+提交历史记录(日志)

1 个答案:

答案 0 :(得分:0)

您已创建了一个项目,并为其添加了一些内容 由于您已克隆空存储库,因此它还没有任何内容。

fatal: bad default revision 'HEAD'

要了解HEAD是什么 - 请在此处阅读:
How to move HEAD back to a previous location? (Detached head)

  

我不明白“上游消失”是什么意思:(

由于您克隆了存储库,因此遥控器上没有名为 master 的分支,因此您必须创建它(答案的结尾)。

如果您已经克隆了现有的仓库,那么您可以将主分支(或任何其他默认分支)结帐到您的项目中。

在您的情况下,如上所述,您克隆了一个空项目,因此您必须先推送主

git push origin master

<强> Why do i need to push the master branch?

第一次 提交您的本地存储库 master 分支,但仍未找到在遥控器上。

  

但是,现在让我说要隐藏所有更改....
  有什么其他选项来撤消上面的提交,所以我将再次有一个干净的结帐

阅读以上有关头部的链接帖子,了解如何操作。

<强> Orphan branch

另一个选择是签出一个孤儿分支(没有任何历史的分支)

git checkout --orphan <new_branch>

你将拥有一个包含文件夹内容但没有任何历史记录的干净分支。

相关问题