简体   繁体   English

git-stash pop后如何恢复丢失的git文件

[英]How to recover the lost git file after git-stash pop

I had 2 branches.我有2个分支。 I recently did git stash on first branch and then moved to different branch.我最近在第一个分支上做了git stash ,然后转移到了不同​​的分支。 I made few changes in the second branch.我在第二个分支中做了一些更改。 And i wanted to move to the first branch so I did git stash again in my second branch and moved to first branch.我想移动到第一个分支,所以我在第二个分支中再次执行git stash并移动到第一个分支。 But after i did git stash pop it merged few files and i lost all my changes after the previous commit.但是在我执行git stash pop它合并了几个文件,并且在上一次提交后我丢失了所有更改。 The got the following message after git stash pop git stash pop 后得到以下消息

git stash pop Auto-merging src/settings.jsx CONFLICT (content): Merge conflict in src/settings.jsx Auto-merging public/css/index.css

I expect to recover all the files that i lost after git stash pop I'm new to git.我希望恢复我在git stash pop之后丢失的所有文件我是 git 的新手。 Any help would be mch appreciated.任何帮助将不胜感激。 Thanks in advance.提前致谢。

Pop will simply return you only last git stash files. Pop 只会返回你最后的 git stash 文件。 So here is what you should do-所以这是你应该做的——

  1. Get the list of all stashes :获取所有 stash 的列表:
$ git stash list

It will return you something like :它会返回给你类似的东西:

stash@{0}: WIP on develop: 049d071 added the index file
stash@{1}: WIP on develop: j264053 Revert "added file_size"
stash@{2}: WIP on develop: 21t80a4 added number to log
  1. Now you can apply whichever stash you want to apply:现在您可以应用您想要应用的任何存储:
git stash apply stash@{2}

Or或者

git stash apply 2

Apply will not remove your stash like pop so you can still revisit it later. Apply 不会像 pop 那样删除你的 stash,所以你以后仍然可以重新访问它。

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

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