1.查找stash commit id
git log --graph --all --decorate --oneline
– graph意思是以图形的模式显示分支,
–all意思是显示所有的commit记录,
–decorate参数用来显示一些相关的信息,如HEAD、分支名、tag名等,
–oneline就是一个commit只显示一行
执行后如下面:
- dd7b26b (master) Extract method
- b0d0487 Rename one of the assertScreenForEvent methods
- ddbb532 Use strong typing for Events
| *-. **0374bd1** (refs/stash) WIP on master: d7fe9ab new class Event
| |\ \
| | | * 2a958c1 untracked files on master: d7fe9ab new class Event
| | * 51510de index on master: d7fe9ab new class Event
| |/
| * d7fe9ab (HEAD) new class Event
| * c59f0f3 Extract method
| * 74a987f Rename one of the assertScreenForEvent methods
| * 75e98b7 Use strong typing for Events
|/
| * 40b5b29 (origin/master, origin/HEAD) added language-chooser
2.切换到该分支
切换到你想恢复的记录,记住前面的id
git checkout 第一步查找出的commitid
3.reset 该commitid
git reset HEAD~1
4.保存修改到stash中
git stash
5.切换到之前的分支
git checkout 分支名称
6.pop stash即可
git stash apply
// 或者
git stash pop