git checkout -b newbranch丢失了当前分支上的更改 [英] git checkout -b newbranch lost changes on current branch

查看:197
本文介绍了git checkout -b newbranch丢失了当前分支上的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以基本上,这就是我发生的事情:

So basically, here's what happened with me:

  1. 我在一个分支上工作,我们称其为'dev'
  2. 我尚未上演或提交更改.但是,我需要为新分支中的某人快速测试一些东西.
  3. 所以我在命令行上执行了git checkout -b testbranch dev
  4. 这从'dev'创建了一个名为'testbranch'的分支,并签出了该分支
  5. 但是,我在'dev'分支中修改过的所有文件(在执行第3点之前我没有存储,暂存和提交)在终端中列出,它们旁边有一个M表示已修改.
  6. 我在测试分支上工作,一旦工作完成,上演并提交了更改,然后又切换回"dev"分支.
  7. 不幸的是,当我查看xcode中的项目时,看起来好像我在创建/切换测试分支之前在dev分支中所做的所有更改都丢失了.

所以我的问题是:我有什么方法可以恢复文件?请注意,我的终端会话仍在运行,并且我将使其保持运行状态,直到获得解决方案以恢复所做的更改或发现这些更改永远丢失为止.帮助!!!!

So my question is: Is there any way for me to recover the files? Note that my terminal session is still running and I will keep it running until I either get a solution to recover my changes or I find out that those changes are lost forever. HELP!!!!

谢谢

-Vivek Kinra

-Vivek Kinra

推荐答案

您的更改不会丢失.

在第3步之后,它们第一次出现在新的 testbranch 上,是因为所做的更改未提交给分支 dev .

The first time they were there on the new testbranch after step 3, it was because the changes weren't committed to branch dev.

接下来,当您将其提交到 testbranch 时,该提交与 testbranch 相关联,因此在 dev 上将不可用在您明确告诉 git 这样做之前先分支.

Next, when you committed those to the testbranch, the commit got associated with testbranch, and thus won't be available on dev branch before you explicitly tell git to do so.

在这种情况下,在我看来,您可以将 testbranch 中的所有代码带入 dev 分支中,这样您就可以做一个简单的合并.

In this case, it seems to me that you are fine with all the code in testbranch to be brought into dev branch, so you can do a simple merge.

git checkout dev
git merge testbranch

这会将所有更改带到 dev 分支.

This will bring all your changes to dev branch.

这篇关于git checkout -b newbranch丢失了当前分支上的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆