博客> 存到了stash里,执行git stash clear
存到了stash里,执行git stash clear
2017-12-13 09:42 评论:0 阅读:382 诸葛亮倒骑小毛驴
ios 存到了stash里 执行git stash clear

今天被git震撼到,脑抽把一天工作的东西存到了stash里,然后执行git stash clear。于是,这种没有commit过的代码都没了。万能的github有篇文章,介绍恢复git stash clear的代码—O网页链接经过测试发现,git会在每次stash的时候偷偷做一个commit,直到gc之前都能拿到对应的信息。奔走相告吧

Recovering a lost stash Abhik B Pramanik edited this page Aug 15, 2011 · 1 revision

Pages 21

  • Home
  • Changing your last commit
  • Checkout out code from a remote repository
  • Committing changes
  • Committing to SVN
  • Configuring Git
  • Creating a local branch
  • Creating a remote branch
  • Creating a SVN branch
  • Diff the logs of two branches
  • Getting commits from SVN
  • Merging a SVN branch
  • Pushing changes to origin master
  • Recovering a lost commit
  • Recovering a lost stash
  • Show 6 more pages…

Clone this wiki locally

Clone in Desktop

Like a commit, a dropped or cleared stash is stored in a Git database until you run git gc. The lost stash is treated like a commit and you can use git fsck to find it.

  • Let's create and drop a stash with a message.

% echo "I'm going to stash this" >> INSTALL % git add INSTALL % git stash save Changes INSTALL % git stash list stash@{0}: On master: Changed INSTALL % git stash clear % git stash list

  • Now we find the stash via git fsck --unreachable | grep commit | cut -d\ -f3 | xargs git show (they'll show up as lost commits).

  • % git fsck --unreachable | grep commit | cut -d\ -f3 | xargs git show commit 0849d9a108d18ed530be24c5b7c8dfa589e130e7 Author: Abhik B Pramanik Date: Mon Aug 15 13:54:56 2011 -0700

    index on master: 183f0cb Lost commit

diff --git a/INSTALL b/INSTALL index bc0edbd..1a56f3d 100644 --- a/INSTALL +++ b/INSTALL @@ -6,3 +6,4 @@ javac Main.class To cleanup the workspace:

rm *.class +I'm going to stash this

commit 7ae2f2a27885383136c3025c5e24f47b29a3ee38 Merge: 183f0cb 0849d9a Author: Abhik B Pramanik Date: Mon Aug 15 13:54:56 2011 -0700

On master: Changed INSTALL
  • Once we find the commit sha1 we can recover it via git stash apply .

  • % git stash apply 7ae2f2a27885383136c3025c5e24f47b29a3ee38

    On branch master

    Your branch is ahead of 'origin/master' by 1 commit.

    #

    Changed but not updated:

    (use "git add ..." to update what will be committed)

    (use "git checkout -- ..." to discard changes in working

    directory)

    #

    modified: INSTALL

    # no changes added to commit (use "git add" and/or "git commit -a")

收藏
2
sina weixin mail 回到顶部