Skip to content

Instantly share code, notes, and snippets.

@josephj
Created July 27, 2012 03:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephj/3186057 to your computer and use it in GitHub Desktop.
Save josephj/3186057 to your computer and use it in GitHub Desktop.
檔案在 git pull 後被刪除、可以用 git fsck 救回來
# 這個時候檔案都已經做完,想要放到 Github 上
josephj@cockatoo /var/www/josephj/frontend/lab/2012/qt-webkit $ % git init .
Initialized empty Git repository in /var/www/josephj/frontend/lab/2012/qt-webkit/.git/
# Github 的 Repo 也已經開好了 (已經產生好 README.md)
josephj@cockatoo /var/www/josephj/frontend/lab/2012/qt-webkit $ % git remote add origin git@github.com:miiicasa/tv-apps-html.git
# 先試著從 Github 上抓東西下來
josephj@cockatoo /var/www/josephj/frontend/lab/2012/qt-webkit $ % git pull
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
Unpacking objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
From github.com:miiicasa/tv-apps-html
* [new branch] master -> origin/master
You asked me to pull without telling me which branch you
want to merge with, and 'branch.master.merge' in
your configuration file does not tell me either. Please
specify which branch you want to merge on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.
If you often merge with the same branch, you may want to
configure the following variables in your configuration
file:
branch.master.remote = <nickname>
branch.master.merge = <remote-ref>
remote.<nickname>.url = <url>
remote.<nickname>.fetch = <refspec>
See git-config(1) for details.
# 此時還沒造成任何損害
josephj@cockatoo /var/www/josephj/frontend/lab/2012/qt-webkit $ % git st
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# animation.html
# border-radius.html
# box-reflect.html
# box-shadow.html
# data-uri.html
# gradient.html
# long-scroll.php
# opacity.html
# switch-view.html
# text-overflow.html
# text-shadow.html
# transition.html
# web-fonts.html
# window-name.php
# word-break.html
# z-index.html
nothing added to commit but untracked files present (use "git add" to track)
# 乖乖地做了 git add . 將所有檔案加入的動作、檔案也都還在
josephj@cockatoo /var/www/josephj/frontend/lab/2012/qt-webkit $ % git add .
josephj@cockatoo /var/www/josephj/frontend/lab/2012/qt-webkit $ % git st
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: animation.html
# new file: border-radius.html
# new file: box-reflect.html
# new file: box-shadow.html
# new file: data-uri.html
# new file: gradient.html
# new file: long-scroll.php
# new file: opacity.html
# new file: switch-view.html
# new file: text-overflow.html
# new file: text-shadow.html
# new file: transition.html
# new file: web-fonts.html
# new file: window-name.php
# new file: word-break.html
# new file: z-index.html
#
# 還沒 Commit 就試著 git pull origin master,就是這個天殺的一步!
josephj@cockatoo /var/www/josephj/frontend/lab/2012/qt-webkit $ % git pull origin master
From github.com:miiicasa/tv-apps-html
* branch master -> FETCH_HEAD
# 阿我那些 git add 的檔案怎麼都消失了!!
josephj@cockatoo /var/www/josephj/frontend/lab/2012/qt-webkit $ % git st
# On branch master
nothing to commit (working directory clean)
# 真的不見了!!!
josephj@cockatoo /var/www/josephj/frontend/lab/2012/qt-webkit $ % ll
總計 16
drwxr-xr-x 3 josephj josephj 4096 2012-07-26 16:20 .
drwxr-xr-x 43 josephj josephj 4096 2012-07-26 11:16 ..
drwxr-xr-x 8 josephj josephj 4096 2012-07-26 16:20 .git
-rw-r--r-- 1 josephj josephj 74 2012-07-26 16:20 README.md
# 還好找到了 git fsck 這個可以拯救我的指令
josephj@cockatoo /var/www/josephj/frontend/lab/2012/qt-webkit $ % git fsck --cache --unreachable
unreachable blob 44b96acee8cac795a9d0c16c5e208afef34bb784
unreachable blob 0b3402edeb706390cc19cd2eafcc8af250ec27b3
unreachable blob 0b863e089a6bdfa1abaf3434d1c3bfa1489c39fe
unreachable blob 0ee5222b8459cb09b041386defa3e4d02fcb8d83
unreachable blob 8e5fc849d4d2e1bb18ec41b8358870830fdef2e2
unreachable blob 51d522c9f2eeec502b7c0c1cfc8f2dcbcd246745
unreachable blob 9fb60d9244fbe2fb9c0b336937c612e822016c64
unreachable blob 20907321e8bee8e7c85d6aaa329d580ba0978a6d
unreachable blob e14ff1a8dc1725cd78d859c3d8ed400f6579e6a5
unreachable blob a31c1d288bdb2fd9c2c2deb2156ad44d43eaffe3
unreachable blob a7e3a598e8ca6a5641ad918b4777873307160f5d
unreachable blob 29feded49bace66ffdf87a20c957fd0f3ce00717
unreachable blob 2c41b662da43e6e312f00dde876520e859bdae0a
unreachable blob ac8b49d35900f0e93755a22639b329e54e35e284
unreachable blob b82dff43ec8d39782ab939db64d62b832256a75f
unreachable blob 7b72b808f9a203e7e3faba60d75ca10c034fe2dd
# 配合 git show <blob> 可以 dump 出被砍掉檔案的內容!就可以一個一個用下面的方法救回來
josephj@cockatoo /var/www/josephj/frontend/lab/2012/qt-webkit $ % git show 44b96acee8cac795a9d0c16c5e208afef34bb784 > window-name.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment