Просмотр исходного кода

Add `git_retrieve_discarded_index_changes`

For all those times when a user accidentally uses `git reset` wrongly.
Weiyi Lou 10 лет назад
Родитель
Сommit
1c7862c271
1 измененных файлов с 14 добавлено и 0 удалено
  1. 14 0
      zsh/custom/git.zsh

+ 14 - 0
zsh/custom/git.zsh

@@ -74,3 +74,17 @@ alias track='git branch --set-upstream-to origin/$(current_branch) && git fetch'
 #
 # ggpush has been removed from oh-my-zsh!
 # ggpush translates into `git push origin <current branch>`.
+
+# Recover indexed/staged changes that were lost.
+#
+# By a careless reset, for example. This function locates all dangling/orphaned
+# blobs and puts them in text files. These files can then be checked for the
+# lost changes.
+#
+# Most tidy method found so far:
+# http://blog.ctp.com/2013/11/21/git-recovering-from-mistakes/
+function git_retrieve_discarded_index_changes() {
+  for blob in $(git fsck --lost-found | awk '$2 == "blob" { print $3 }'); do
+    git cat-file -p $blob > $blob.txt;
+  done
+}