移动到不同的分支,丢失更改 - 有没有办法返回?
Moved to different branch, lost changes - is there a way back?
我当时在 master 分支工作,并没有意识到这一点。我在那个分支做了几个小时的工作。
当我完成我想提交的内容后,我转到 GitHub Desktop v2.2.3 并注意到我在 master 中。在将它们添加到暂存区之前,我列出了可用的分支并选择了我想要的;它问我想对当前的更改做什么,我选择了一个选项说我想 "bring them with me".
现在我在两个分支中都找不到我的更改。
我转到命令行并输入 "git reflog" 并得到以下内容:
e328567 (HEAD -> master, origin/master, origin/HEAD, origin/branchNumberOne, branchNumberOne) HEAD@{0}: checkout: moving from branchNumberOne to master
e328567 (HEAD -> master, origin/master, origin/HEAD, origin/branchNumberOne, branchNumberOne) HEAD@{1}: checkout: moving from master to branchNumberOne
e328567 (HEAD -> master, origin/master, origin/HEAD, origin/branchNumberOne, branchNumberOne) HEAD@{2}: reset: moving to HEAD
e328567 (HEAD -> master, origin/master, origin/HEAD, origin/branchNumberOne, branchNumberOne) HEAD@{3}: clone: from https://gitlab.myURL.com/aCompany/myProject.git
我什至不确定要使用哪个 HEAD 索引来尝试取回我的更改;我怎么弄清楚?或者有其他方法可以恢复更改吗?
上次发生在我身上的 IntelliJ 拯救了我,如果你使用任何 IDE 你可以撤消丢失文件的更改。通过执行 "undo" 或使用文件历史记录功能。
如果您将在 git reflog
输出中看到 *ALL 提交指向相同的 SHA-1,这意味着 [=11] 上未进行任何更改=]
这是因为你所有的分支都指向同一个 SHA-1
确定您想成为哪个分支并检查一下。
就这么简单
您的问题是您没有提交更改。你将无法取回它们,除非你将它们藏起来,或者如果你没有它们,比如在你的 IDE 历史记录中。
事实证明,如果您更改分支并且没有 select 我确信我有 selected 的选项,Github Desktop 会存储更改。所以他们被藏起来了,但我没有意识到。我现在有更改。
感谢所有提供有用提示和评论的人。 @saurabh P Bhandari,如果你想把你的隐藏建议放在答案中,我会接受它并删除这个。
引用自 GitHub 桌面帮助 page,
Switching between branches
If you have uncommitted, saved changes,
you'll need to decide what to do with your changes before you can
switch branches. You can commit your changes on the current branch,
stash your changes on the current branch, or bring the changes to your
new branch.
事实证明,这两个选项(上面突出显示的)都在内部为各自的分支执行存储操作。
之前 v2.2.2 已报告 GitHub 桌面在切换操作期间丢弃提交的问题 here。
如果使用 this, then you can switch to git CLI as suggested here and try listing the stashes ( make sure you are on the branch you want the uncommitted changes) by using the command git stash list
. If the stash is available, then you could either pop
or apply
未找到未提交的更改,这取决于您是要删除存储还是保留它以供进一步使用。
注意:
- GitHub Destkop 应用的“帮助”菜单下的日志可能会提供有关幕后发生的事情的更多信息。
- 以防万一,如果日志显示存储操作失败(通过丢弃未提交的更改),可能仍然可以 recover 更改。
我当时在 master 分支工作,并没有意识到这一点。我在那个分支做了几个小时的工作。
当我完成我想提交的内容后,我转到 GitHub Desktop v2.2.3 并注意到我在 master 中。在将它们添加到暂存区之前,我列出了可用的分支并选择了我想要的;它问我想对当前的更改做什么,我选择了一个选项说我想 "bring them with me".
现在我在两个分支中都找不到我的更改。
我转到命令行并输入 "git reflog" 并得到以下内容:
e328567 (HEAD -> master, origin/master, origin/HEAD, origin/branchNumberOne, branchNumberOne) HEAD@{0}: checkout: moving from branchNumberOne to master
e328567 (HEAD -> master, origin/master, origin/HEAD, origin/branchNumberOne, branchNumberOne) HEAD@{1}: checkout: moving from master to branchNumberOne
e328567 (HEAD -> master, origin/master, origin/HEAD, origin/branchNumberOne, branchNumberOne) HEAD@{2}: reset: moving to HEAD
e328567 (HEAD -> master, origin/master, origin/HEAD, origin/branchNumberOne, branchNumberOne) HEAD@{3}: clone: from https://gitlab.myURL.com/aCompany/myProject.git
我什至不确定要使用哪个 HEAD 索引来尝试取回我的更改;我怎么弄清楚?或者有其他方法可以恢复更改吗?
上次发生在我身上的 IntelliJ 拯救了我,如果你使用任何 IDE 你可以撤消丢失文件的更改。通过执行 "undo" 或使用文件历史记录功能。
如果您将在 git reflog
输出中看到 *ALL 提交指向相同的 SHA-1,这意味着 [=11] 上未进行任何更改=]
这是因为你所有的分支都指向同一个 SHA-1
确定您想成为哪个分支并检查一下。 就这么简单
您的问题是您没有提交更改。你将无法取回它们,除非你将它们藏起来,或者如果你没有它们,比如在你的 IDE 历史记录中。
事实证明,如果您更改分支并且没有 select 我确信我有 selected 的选项,Github Desktop 会存储更改。所以他们被藏起来了,但我没有意识到。我现在有更改。
感谢所有提供有用提示和评论的人。 @saurabh P Bhandari,如果你想把你的隐藏建议放在答案中,我会接受它并删除这个。
引用自 GitHub 桌面帮助 page,
Switching between branches
If you have uncommitted, saved changes, you'll need to decide what to do with your changes before you can switch branches. You can commit your changes on the current branch, stash your changes on the current branch, or bring the changes to your new branch.
事实证明,这两个选项(上面突出显示的)都在内部为各自的分支执行存储操作。
之前 v2.2.2 已报告 GitHub 桌面在切换操作期间丢弃提交的问题 here。
如果使用 this, then you can switch to git CLI as suggested here and try listing the stashes ( make sure you are on the branch you want the uncommitted changes) by using the command git stash list
. If the stash is available, then you could either pop
or apply
未找到未提交的更改,这取决于您是要删除存储还是保留它以供进一步使用。
注意:
- GitHub Destkop 应用的“帮助”菜单下的日志可能会提供有关幕后发生的事情的更多信息。
- 以防万一,如果日志显示存储操作失败(通过丢弃未提交的更改),可能仍然可以 recover 更改。