简体   繁体   English

将第一个提交存储在一个空的项目存储库中

[英]Stash the very first commit on an empty project repo

I am new to git and try to understand how I ll undo /stash changes + logs lets say I have a very fresh branch with no commits yet eg 我是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

(I don't understand what does "upstream is gone" mean :( ) (我不明白“上游消失了”是什么意思:()

However, now lets say I want to stash all changes. 但是,现在让我说要隐藏所有更改。 One simple solution is to delete the clone and re-clone from remote repo . 一种简单的解决方案是删除克隆,然后从远程repo重新克隆。 What are other options to undo the above commit so I ll again have a clean checkout (without commits + commit history (logs) 有什么其他选项来撤消上面的提交,所以我将再次有一个干净的结帐(没有提交+提交历史记录(日志)

You have created a project and added some content to it. 您已经创建了一个项目,并向其中添加了一些内容。
Since you have clone an empty repository it does not have any content yet. 由于您已经克隆了一个空的存储库,因此它没有任何内容。

fatal: bad default revision 'HEAD'

To understand what HEAD is - read about in here: 要了解HEAD是什么,请在此处阅读:
How to move HEAD back to a previous location? 如何将HEAD移回以前的位置? (Detached head) (独立头)

I don't understand what does "upstream is gone" mean :( 我不明白“上游消失了”是什么意思:(

Since you have cloned an empty repository there is no such branch named master on the remote so you have to create it (end of the answer). 由于您已经克隆了一个空的存储库,因此远程上没有这样的名为master的分支,因此您必须创建它(答案的结尾)。

If you would have cloned an existing repo you would have gotten the master branch (or any other default branch) checkout out to your project. 如果您将克隆现有的存储库,则将获得master分支(或任何其他默认分支)签出到您的项目。

In your case as explained above you have cloned an empty project so you have to first push master 在您的情况下,如上所述,您克隆了一个空项目,因此您必须首先推送master

git push origin master

Why do i need to push the master branch?

The first commit to your local repository created master branch and it still not found on the remote. 一次提交到本地存储库创建了master分支,但仍然无法在远程上找到它。


However, now lets say I want to stash all changes.... 但是,现在让我说我想隐藏所有更改...。
What are other options to undo the above commit so I ll again have a clean checkout 有什么其他选项来撤消上面的提交,所以我将再次有一个干净的结帐

Read the above linked post about head to learn how to do it. 阅读以上有关头部的链接文章,了解如何进行操作。


Orphan branch

Another option is to checkout an orphan branch (branch without any history) 另一种选择是签出一个孤立分支(无任何历史分支)

git checkout --orphan <new_branch>

And you will have a clean branch with the content of the folder but without any history. 并且您将拥有一个包含文件夹内容的干净分支,但没有任何历史记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM