How to do it...

  1. First, we'll check whether we have made any changes to files in the working tree (just for the clarity of the example) and the history of the repository:
$ git status 
On branch master 
Your branch is up-to-date with 'origin/master'. 

nothing to commit, working directory clean 

$ git log --oneline 
3061dc6 Adds Java version of 'hello world' 
9c7532f Fixes compiler warnings 
5b5d692 Initial commit, K&R hello world 
  1. Now, we'll undo the commit and retain the changes introduced to the working tree:
$ git reset --mixed HEAD^  

$ git log --oneline 
9c7532f Fixes compiler warnings 
5b5d692 Initial commit, K&R hello world 

$ git status 
On branch master 
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded. 

  (use "git pull" to update your local branch)  

Untracked files: 

  (use "git add <file>..." to include in what will be committed) 
 
    HelloWorld.java 
    Makefile 

nothing added to commit but untracked files present (use "git add" to track) 

We can see that our commit has been undone, but the changes to the file are preserved in the working tree, so more work can be done in order to create a proper commit.

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

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