git 结帐只是删除了我的存储库吗?

Did git checkout just delete my repository?

General Question: How can one use Git locally alone (i.e. by oneself) in such a way that merging changes from a new branch into master, or moving from branch to branch using checkout, doesn't delete everything in the new branch and the master branch?

Or if one wants to avoid git deleting everything and leaving no backups, is it essentially necessary to be working with a remote repository (e.g. GitHub), not just a local one?

具体案例:
我的本地 git 存储库有两个分支,masterequality,位于文件夹 .../ps/ps3 中。我在分支 equality 中,我想将我的更改合并到 master.

所以首先我做了 git merge 并且这返回了错误:

fatal: No remote for the current branch.

然后我想我需要在 master 而不是 equality 中才能将我从 equality 的更改合并到 master 中。所以我接下来做的是:git checkout master。这产生了以下错误:

error: Your local changes to the following files would be overwritten by checkout: ps3/ps3.aux ps3/ps3.log ps3/ps3.pdf ps3/ps3.synctex.gz ps3/ps3.tex Please commit your changes or stash them before you switch branches. Aborting

我对该错误的解释如下:什么都没发生,我仍在 equality 分支中,如果我想在 equality 中进行更改,我应该再次提交 equality 分支当我使用它们重写 master 分支而不是 git 从 equality.

的早期版本重写时被保存

我的终端提示表明我还在目录.../ps/ps3和分支equality中,所以我认为没有任何问题。当我执行 git commit -am "Finished correct proof" 时,我没有收到错误消息。

5 files changed, 155 insertions(+), 29 deletions(-) rewrite ps3/ps3.pdf (72%)

Now it was either this command, or the one immediately following it, which deleted everything, not just equality and every commit in that branch, but also master and every commit in the branch, and even the entire folder .../ps/ps3 of the repository.

我做了git merge(我还在分支equality),我得到了错误信息:

fatal: No remote for the current branch.

这让我感到困惑,因为为什么我需要远程控制才能做任何事情?和我现在的处境有什么关系?我猜这只是抱怨将 equality 的更改合并到 master 需要从 master 完成的一种神秘方式。

所以接下来我做了 git checkout master 并且没有错误,只是 Switched to branch 'master'。尽管没有出现任何错误,但我仍然认为这可能是删除所有内容的步骤,因为在执行此操作后我的终端不再显示我处于 equalitymaster,所以看起来必须至少删除整个存储库,即其中的所有文件和包含的文件夹。

我的终端仍然说我在一个名为 ps3 的目录中,尽管它也没有像它应该的那样列出一个 git 分支。所以接下来我做了 git merge 然后 git merge equality 但都返回了错误:

fatal: Unable to read current working directory: No such file or directory

然后我做了 ls,没有输出,然后我做了 cd ..ls -a,目录 ps3 没有被列为 ps。 IE。存储库的包含文件夹,以及其中的所有内容和每个分支都以某种方式被删除。我什至不知道可以用 Git 做到这一点——我认为如果我搞砸了可能发生的最糟糕的事情是 master 分支中的早期版本会覆盖equality 分支中的较新版本,然后我可以多次执行 git revert 以取回 equality 分支。我认为 git checkout 只是在分支之间移动,而不是删除所有内容。

This page makes it seem like git checkout master does what I expected it to do, namely switch to the master branch, rather than deleting everything. Also 看起来 git checkout 应该有助于恢复文件,那为什么它删除了我的所有文件?

首先,语法:你是对的 git merge 需要在目标 b运行ch 上是 运行 (然后你必须给它 b 的名称运行ch 你想带进来)。

发生了什么:当您 运行 git checkout master 时,您位于工作副本的子目录中,并且它删除了该子目录,因为 master 那里没有任何文件。 ("unable to read current working directory" 是当您删除目录而其中有 shell 时发生的情况。)

好消息:什么都没有丢失。您只是仍在存储库中,而不是在存储库之外查看它曾经占用的 space。现在是 运行 git merge equality 的时候了,你会看到 ps3 回来。

坏消息:您提交了生成的文件(.aux.log 等)。 Don't do that;也许你应该在合并之前回到 equalitygit commit --amend 它们不存在的状态。 (合并后很难很好地修复。)