How to do it...

  1. Let's look for the unreachable objects in the database:
$ git fsck --unreachable 

Checking object directories: 100% (256/256), done. 
unreachable commit 147240ad0297f85c9ca3ed513906d4b75209e83d 
unreachable blob b16cf63ab66605f9505c17c5affd88b34c9150ce 
unreachable commit 4c3b1e10d8876cd507bcf2072c85cc474f7fb93b 
The object's ID, the SHA-1 hash, will not be the same if you perform the example on your computer, as the committer, author, and timestamp will be different.
  1. We found two commits and one blob. Let's take a closer look at each of them; the blob first:
$ git show b16cf63ab66605f9505c17c5affd88b34c9150ce 

#include <stdio.h> 
void say_hello(void) { 
  printf("hello, worldn"); 
} 
 
int main(void){ 
  say_hello(); 
   return 0; 
} 

So, the blob is the hello_world.c file from the example, which stashes away your changes before resetting a commit. Here, we stashed away the file, performed a reset, and resurrected the file from the stash, but we never actually performed a commit. The stash command, however, did add the file to the database, so it could find it again, and the file will continue to be there until the garbage collection kicks in, or forever if it is referenced by a commit in the general history.

  1. Let's look more closely at the two commits:
$ git show 147240ad0297f85c9ca3ed513906d4b75209e83d 

commit 147240ad0297f85c9ca3ed513906d4b75209e83d 
Merge: 3061dc6 4c3b1e1 
Author: John Doe <[email protected]> 
Date:   Thu Mar 13 23:19:37 2014 +0100 
     WIP on master: 3061dc6 Adds Java version of 'hello world' 

diff --cc hello_world.c 
index 881ef55,881ef55..b16cf63 
--- a/hello_world.c 
+++ b/hello_world.c 
@@@ -1,7 -1,7 +1,10 @@@ 

#include <stdio.h> --int main(void){ ++void say_hello(void) { printf("hello, worldn"); ++} ++int main(void){ ++ say_hello(); return 0; --} ++} $ git show 4c3b1e10d8876cd507bcf2072c85cc474f7fb93b commit 4c3b1e10d8876cd507bcf2072c85cc474f7fb93b Author: John Doe <[email protected]> Date: Thu Mar 13 23:19:37 2014 +0100 index on master: 3061dc6 Adds Java version of 'hello world'

Both of the commits are actually commits we made when we stashed away our changes in the previous example. The stash command creates a commit object with the content of the staging area, and a merge commit merging HEAD and the commit with the index with the content of the working directory (tracked files only). As we resurrected our stashed changes in the previous example, we no longer have any reference pointing at the preceding commits; therefore, they are found by git fsck.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.119.17