title: How to cancel a local git commit?
body: <p>My issue is I have changed a file e.g.: README, added a new line '<em>this for my testing line</em>' and saved the file, then I issued the following commands:</p>
  <pre><code>git status
  
  # On branch master
  # Changed but not updated:
  #   (use &quot;git add &lt;file&gt;...&quot; to update what will be committed)
  #   (use &quot;git checkout -- &lt;file&gt;...&quot; to discard changes in working directory)
  #
  #   modified:   README
  #
  no changes added to commit (use &quot;git add&quot; and/or &quot;git commit -a&quot;)
  
  
  git add README
  
  git commit -a -m 'To add new line to readme'
  </code></pre>
  <p>I didn't push the code to GitHub. Now I want to cancel this commit.</p>
  <p>For this, I used</p>
  <pre><code>git reset --hard HEAD~1
  </code></pre>
  <p>But I lost the newly added line '<em>this for my testing line</em>' from the README file.
  This should not happen. I need the content to be there. <strong>Is there a way to retain the content and cancel my local commit?</strong></p>