简体   繁体   English

如何获取使用“ git add”添加的文件,“ git commit”失败,由于来自远程的错字和git pull

[英]How to get the files that are added using “git add .”, failed “git commit” due to typo and git pull from remote

I have lost major changes I have made. 我丢失了所做的重大更改。 I list out the series of git commands I used. 我列出了我使用的一系列git命令。

  1. git add . git添加
  2. git commit -mm "message" {this failed I guess due to -mm but I didnt see anything on console} git commit -mm“ message” {我猜这是由于-mm导致的,但是我在控制台上没看到任何东西}
  3. git pull origin master {to get changes from master} This showed I have changes on bundle.js an dbundle.map.js. git pull origin master {从master获得更改}这表明我对bundle.js和dbundle.map.js进行了更改。 So I deleted them. 所以我删除了它们。 I did a "git stash". 我做了一个“ git stash”。 But by now I noticed all other files were modified with contents on remote repo {as I did git pull origin master} 但是到现在,我注意到所有其他文件都被远程仓库中的内容修改了(就像我做的git pull origin master一样)

I tried looking lost-found but I could not see the blob which has my changes. 我尝试着找寻失物招领处,但看不到有变化的斑点。 Is it possible to retrieve the lost content? 是否可以找回丢失的内容? How can I retrieve? 我该如何找回?

From the command you did, i notice the usage of git stash . 从您执行的命令中,我注意到git stash的用法。 Git stash will move the changes you made away from the current working directory. Git隐藏将您所做的更改从当前工作目录移开。

You can view the last stashed content by: 您可以通过以下方式查看最近存放的内容:

git stash show

and see if your changes is there. 看看您的更改是否在那里。

If it does, do a 如果是这样,请执行

git stash apply

For deleted bundle.js. 对于已删除的bundle.js。 I don't see a way to retrieve changed the file. 我没有找到找回更改过的文件的方法。 You can check trash (or something similar in your os). 您可以检查垃圾(或操作系统中的类似内容)。

However, you can always get the last committed state on bundle.js by checking out from the HEAD 但是,您始终可以通过从HEAD检出来获得bundle.js的最后提交状态

git checkout bundle.js

Side note 边注

I have seen a good Git Gui that can help you easily browse stashed changes and check out from there. 我看到了一个不错的Git Gui,它可以帮助您轻松浏览隐藏的更改并从那里签出。 The software is Git Eye. 该软件是Git Eye。 However, it is been several years I haven't use Git Eye as now. 但是,已经有好几年没有像现在这样使用Git Eye了。 I'm getting more comfortable with command line. 我对命令行越来越满意。

Thank you Yana 谢谢亚娜

The sequence of steps I used are 我使用的步骤顺序是

  • git stash show {showed all files being stashed} git stash show {显示所有被隐藏的文件}
  • git stash show -p {made sure all the changes are there} git stash show -p {确保所有更改都在那里}
  • Created a new branch and saved the stashed content to new branch. 创建一个新分支并将隐藏的内容保存到新分支。
  • git add . git添加 & git commit -m "updated one" {as I had bundle.js modified} &git commit -m“更新了一个”(因为我修改了bundle.js)
  • git stash pop git stash pop

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

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