[英]Stash the very first commit on an empty project repo
我是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
(我不明白“上游消失了”是什么意思:()
但是,现在让我说要隐藏所有更改。 一种简单的解决方案是删除克隆,然后从远程repo重新克隆。 有什么其他选项来撤消上面的提交,所以我将再次有一个干净的结帐(没有提交+提交历史记录(日志)
您已经创建了一个项目,并向其中添加了一些内容。
由于您已经克隆了一个空的存储库,因此它没有任何内容。
fatal: bad default revision 'HEAD'
要了解HEAD是什么,请在此处阅读:
如何将HEAD移回以前的位置? (独立头)
我不明白“上游消失了”是什么意思:(
由于您已经克隆了一个空的存储库,因此远程上没有这样的名为master的分支,因此您必须创建它(答案的结尾)。
如果您将克隆现有的存储库,则将获得master分支(或任何其他默认分支)签出到您的项目。
在您的情况下,如上所述,您克隆了一个空项目,因此您必须首先推送master
git push origin master
Why do i need to push the master branch?
第一次提交到本地存储库创建了master
分支,但仍然无法在远程上找到它。
但是,现在让我说我想隐藏所有更改...。
有什么其他选项来撤消上面的提交,所以我将再次有一个干净的结帐
阅读以上有关头部的链接文章,了解如何进行操作。
Orphan branch
另一种选择是签出一个孤立分支(无任何历史分支)
git checkout --orphan <new_branch>
并且您将拥有一个包含文件夹内容的干净分支,但没有任何历史记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.