{"id":35604,"date":"2016-04-01T16:09:41","date_gmt":"2016-04-01T13:09:41","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=35604"},"modified":"2019-04-23T14:54:28","modified_gmt":"2019-04-23T11:54:28","slug":"git-undo-commit-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/","title":{"rendered":"Git Undo Commit Example"},"content":{"rendered":"<h2>1. Introduction<\/h2>\n<p>Every human being&nbsp;may make mistakes, especially the Software developers:) When we&#8217;re writing code, it&#8217;s a process of how we&#8217;re thinking and how we solve specific problems. In real life, it could be a disaster if we make some irrecoverable mistakes. However, this will not happen in writing code for the developers, especially with the help of Git.<\/p>\n<p>In this article, we will focus on how to revert what we have done to the previous status. This may &nbsp;be caused by that we have made wrong update to our code, or we have deleted the existed code by accident, or even it could be you made some inappropriate comments to the code. This could be really awful if we don&#8217;t have ways to solve it. However, <code>Git<\/code> undo command makes this easy to recover to the previous version of the code. So you don&#8217;t need to worry about what you&#8217;ve done.\n<\/p>\n<h2>2. Git undo examples<\/h2>\n<h3>2.1 Introduction on git directory<\/h3>\n<p>Before we dig into the <code>Git<\/code> undo commit operations, we need to have a general idea on the three different directories that a <code>git<\/code> system has: workspace, index\/staging area and the local repository. The whole structure could be referred to the following figure, this figure comes out of the link on it. Detailed information could be found in <a href=\"http:\/\/blog.osteele.com\/posts\/2008\/05\/my-git-workflow\/\" target=\"_blank\" rel=\"noopener noreferrer\">this link<\/a>. It&#8217;s a great article for beginners on git.<\/p>\n<p><figure id=\"attachment_35629\" aria-describedby=\"caption-attachment-35629\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/gir-repository.jpg\" rel=\"attachment wp-att-35629\"><img decoding=\"async\" class=\"wp-image-35629 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/gir-repository.jpg\" alt=\"git repository\" width=\"800\" height=\"738\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/gir-repository.jpg 800w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/gir-repository-300x277.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/gir-repository-768x708.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption id=\"caption-attachment-35629\" class=\"wp-caption-text\">Git repository<\/figcaption><\/figure><\/p>\n<p>To understand further of Git, we need to be very clear about the directories.<\/p>\n<ul>\n<li>Workspace: it&#8217;s the place where you see in your computer system, or the directory where you check out your files. Files in the workspace could be added to the <code>Git<\/code> by using <code>git add<\/code> command.<\/li>\n<li>Index: it&#8217;s also called stating area. It&#8217;s an invisible space where you can add files that you want to commit. To add commit, you can use <code>git commit<\/code> command.<\/li>\n<li>Local repository: it&#8217;s also an invisible repository. Actually it&#8217;s stored in the .git folder, which is hidden in the folder you created.<\/li>\n<li>Remote repository: this could be another computer, or it could be the server of others, such as Github, which we can consider it as a remote repository. To access to the remote repository, <code>git push<\/code> or <code>git pull<\/code> could be used<\/li>\n<\/ul>\n<p>Here, we also need to get familiar with the concept of head, which is the pointer to the most recent commit on the current branch. It&#8217;s actually a hash value of current commit, which is calculated by SHA-1 hash on a file with a hash value of 160 bits that uniquely identifies the contents of the file.<\/p>\n<h3>2.2 Create git folder<\/h3>\n<p>To get started, we need to create a git repository firstly. So we go ahead and create a folder on our local machine with the name of GitLearning. Then we initialize the folder to make it a git repository with command <code>git init<\/code>. After this, you&#8217;ve created an empty git repository successfully. Wonderful!<\/p>\n<p>The whole process and the command is shown below:<\/p>\n<pre class=\"brush:bash\">WXMs-MacBook-Pro:~ WXM$ cd Documents\/\nWXMs-MacBook-Pro:Documents WXM$ cd GitLearning\/\nWXMs-MacBook-Pro:GitLearning WXM$ ls\nWXMs-MacBook-Pro:GitLearning WXM$ git init\nInitialized empty Git repository in \/Users\/WXM\/Documents\/GitLearning\/.git\/\nWXMs-MacBook-Pro:GitLearning WXM$ ls -ah\n.\t..\t.git\n<\/pre>\n<p>Note that <code>ls -ah<\/code> is needed to make the .git folder visible. Otherwise, it can not been seen, and this is for security. If you change the content in .git folder, the whole git repository would be crush.<\/p>\n<p>Then we create a empty txt file named README.txt. This is normal for software developers and also useful for others to check the usage of the code. So don&#8217;t forget to create readme file along with you code. After this, you can add any content into the txt file. For example, here we add a sentence with &#8220;This is a readme file.&#8221; in the file. To make it a real file in git system, we need to use <code>git add<\/code> and <code>git commit<\/code> commands, to add the file into the staging area and local repository, respectively. The whole procedure could be checked by the command below:<\/p>\n<pre class=\"brush:bash\">pcp352933pcs:GitLearning WXM$ vi READMEFILE.txt\npcp352933pcs:GitLearning WXM$ ls\nREADMEFILE.txt\npcp352933pcs:GitLearning WXM$ git add READMEFILE.txt \npcp352933pcs:GitLearning WXM$ git commit -m \"First time writing readme file\"\n[master d907151] First time writing readme file\n 1 file changed, 1 insertion(+)\n create mode 100644 READMEFILE.txt\n<\/pre>\n<p>In the bash above, <code>git add READMEFILE.txt<\/code> add the READMEFILE.txt into the stating area, while the git commit -m &#8220;First time writing readme file&#8221; command add the READMEFILE.txt into the local repository.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Then if I run <code>git status<\/code> command to check the status of my git system, it shows that:<\/p>\n<pre class=\"brush:bash\">pcp352933pcs:GitLearning WXM$ git status\nOn branch master\nYour branch is ahead of 'origin\/master' by 1 commit.\n  (use \"git push\" to publish your local commits)\nnothing to commit, working directory clean\n<\/pre>\n<p>It shows that nothing to commit and working directory is clean. However, it also shows that your branch is ahead of &#8216;origin\/master&#8217; by 1 commit and use &#8220;git push&#8221; to publish your local commits. The reason for this is that I&#8217;ve connected this folder with my Github account, which is the remote repository. Because I haven&#8217;t add the file to the remote repository, so it will remind you of that. It also shows that using <code>git push<\/code> command it will publish the local changes to the remote repository. After running the <code>git push<\/code>, everything is good now:<\/p>\n<pre class=\"brush:bash\">pcp352933pcs:GitLearning WXM$ git push\nCounting objects: 3, done.\nDelta compression using up to 4 threads.\nCompressing objects: 100% (2\/2), done.\nWriting objects: 100% (3\/3), 309 bytes | 0 bytes\/s, done.\nTotal 3 (delta 1), reused 0 (delta 0)\nTo https:\/\/github.com\/******\/GitLearning.git\n   5a5a9ea..d907151  master -&gt; master\n<\/pre>\n<p>Then when you check the status again, it&#8217;ll show you that everything works cleanly now.<\/p>\n<pre class=\"brush:bash\">pcp352933pcs:GitLearning WXM$ git status\nOn branch master\nYour branch is up-to-date with 'origin\/master'.\nnothing to commit, working directory clean\n<\/pre>\n<h3>2.3 Git undo commit<\/h3>\n<p>In some cases, we want to change our minds and revert the commit we have made, then git makes this easy to operate on. This is called git undo commit.<\/p>\n<p>To make this happen, we add another line to the READMEFILE.txt, with &#8220;Bad words for others&#8221;. Then we add the file to the stating area and to the local repository. The following is the process that we have done:<\/p>\n<pre class=\"brush:bash\">pcp352933pcs:GitLearning WXM$ git add READMEFILE.txt \npcp352933pcs:GitLearning WXM$ git commit -m \"Add bad words\"\n[master 1f50e80] Add bad words\n 1 file changed, 1 insertion(+)\npcp352933pcs:GitLearning WXM$ cat READMEFILE.txt \nThis is a readme file.\nBad words for others.\n<\/pre>\n<p>When we use <code>git commit<\/code> command it shows that 1 file changes, 1 insertion(+). That&#8217;s because we&#8217;ve added one line with &#8220;Band words for others&#8221;. Using the <code>cat<\/code> command to show where we&#8217;ve changed the file.<\/p>\n<p>Again, <code>git status<\/code> could be used to check the status:<\/p>\n<pre class=\"brush:bash\">pcp352933pcs:GitLearning WXM$ git status\nOn branch master\nYour branch is ahead of 'origin\/master' by 1 commit.\n  (use \"git push\" to publish your local commits)\nnothing to commit, working directory clean\n<\/pre>\n<p>If we want to make sure what change we have made, then we could use <code>git diff<\/code> to check the difference between current version with the previous one. For <code>git diff<\/code>, more detailed instructions could be found in <a href=\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-diff-example\/\" target=\"_blank\" rel=\"noopener noreferrer\">my other article about git diff example<\/a>.<\/p>\n<p>Then we add another line to the txt file with &#8220;I made changes again:)&#8221;. To check the difference, the following is how we do it:<\/p>\n<pre class=\"brush:bash\">pcp352933pcs:GitLearning WXM$ git diff\ndiff --git a\/READMEFILE.txt b\/READMEFILE.txt\nindex 4cc46cb..6b972f7 100644\n--- a\/READMEFILE.txt\n+++ b\/READMEFILE.txt\n@@ -1,2 +1,3 @@\n This is a readme file.\n Bad words for others.\n+I made changes again:)\n<\/pre>\n<p>Then we can see that the sentence with &#8220;+&#8221; shows that where we add content to the file.<\/p>\n<p>Then if we made another change to the the txt file and add another line with &#8220;I love changing things.&#8221; Until now we&#8217;ve made three changes &#8211; adding three lines compared with the first version. The four commits are :&nbsp;Love making changes &lt;-&nbsp;Made changes again &lt;-&nbsp;Add bad words &lt;-&nbsp;First time writing readme file, where the arrow shows the order of the changes.<\/p>\n<p>In real life of development, thousands lines of code could be changed. We can not remember it rightly. So <code>git log<\/code> should be useful right now, and it&#8217;ll show all the change history we have made. We can try it with our own example here:<\/p>\n<pre class=\"brush:bash\">pcp352933pcs:GitLearning WXM$ git log\ncommit 67713e5af45b67aa2628b12a73d4b493a16de159\nAuthor: Jun &lt;wuxiaomin98@hotmail.com&gt;\nDate:   Wed Mar 30 17:19:12 2016 -0500\n\n    Love making changes\n\ncommit 47640c18cf433c6f6c7ba26b34f886688d34a1d3\nAuthor: Jun &lt;wuxiaomin98@hotmail.com&gt;\nDate:   Wed Mar 30 17:18:38 2016 -0500\n\n    Made changes again\n\ncommit 1f50e80eb551e3ed7981251378d4609e30248d2f\nAuthor: Jun &lt;wuxiaomin98@hotmail.com&gt;\nDate:   Wed Mar 30 16:58:21 2016 -0500\n\n    Add bad words\n\ncommit d90715179d20e10c5d88fc8d8a58972605fb38c0\nAuthor: Jun &lt;wuxiaomin98@hotmail.com&gt;\nDate:   Wed Mar 30 16:32:28 2016 -0500\n\n    First time writing readme file\n<\/pre>\n<p>The above file shows every change we&#8217;ve made with specific date and time. You should notice the long sequence of strings after the commit. That&#8217;s the commit id, which corresponds to specific commit. Why it&#8217;s not in 1, 2, 3&#8230; order? That&#8217;s because <code>Git<\/code> is a distributed system. If every commit id is in order, when multiple changes happen, there should be conflict.[ulp id=&#8217;pzgfvmZhgslwSymm&#8217;]<\/p>\n<p>Sometime, the changes are quite a lot and what we want is just to check the changes. Then <code>git log --pretty=oneline<\/code> could be utilized to show each commit in one line.<\/p>\n<pre class=\"brush:bash\">pcp352933pcs:GitLearning WXM$ git log --pretty=oneline\n67713e5af45b67aa2628b12a73d4b493a16de159 Love making changes\n47640c18cf433c6f6c7ba26b34f886688d34a1d3 Made changes again\n1f50e80eb551e3ed7981251378d4609e30248d2f Add bad words\nd90715179d20e10c5d88fc8d8a58972605fb38c0 First time writing readme file\n<\/pre>\n<p>See how convenient it could be!<\/p>\n<p>Then if we want to go back to the previous version, <code>git reset<\/code> command could be used. What we use here is <code>git reset --hard HEAD^<\/code>. HEAD is means the commit of current branch. Symbol &#8220;^&#8221; means go back to the previous one version, &#8220;^^&#8221; means the previous two version and so on so forth. While it&#8217;s hard to continue with multiple &#8220;^&#8221; symbols when there&#8217;s hundreds and thousands versions. Then you can use the number directly. For example <code>git reset --hard HEAD^<\/code> is the same as <code>git reset --hard HEAD~1<\/code> and <code>git reset --hard HEAD^^<\/code> is the same as git reset &#8211;hard HEAD~2. Pay attention to the symbol &#8220;~&#8221; before the numbers and do not forget to add it.<\/p>\n<p>For our own example, right now the head is in 67713e5af45b67aa2628b12a73d4b493a16de159 Love making changes. If we want to go back to the previous version. Run the <code>git reset --hard HEAD^<\/code> command and check the result.<\/p>\n<pre class=\"brush:bash\">pcp352933pcs:GitLearning WXM$ cat READMEFILE.txt \nThis is a readme file.\nBad words for others.\nI made changes again:)\nI love changing things.\npcp352933pcs:GitLearning WXM$ git reset --hard HEAD^\nHEAD is now at 47640c1 Made changes again\npcp352933pcs:GitLearning WXM$ cat READMEFILE.txt \nThis is a readme file.\nBad words for others.\nI made changes again:)\n<\/pre>\n<p>We can see from the above, that after we run the <code>git reset<\/code> command, it goes back to the previous version Made changes again. The 47640c1 is exactly the shortcut commit id for the previous commit.<\/p>\n<p>Then if we want to go back to the initial status, we can go back twice with command <code>git reset --hard HEAD~2<\/code><\/p>\n<pre class=\"brush:bash\">pcp352933pcs:GitLearning WXM$ git reset --hard HEAD~2\nHEAD is now at d907151 First time writing readme file\npcp352933pcs:GitLearning WXM$ cat READMEFILE.txt \nThis is a readme file.\n<\/pre>\n<p>Now job has done! Fantastic!<\/p>\n<p>Then run <code>git log<\/code>, it shows only the first version.<\/p>\n<pre class=\"brush:bash\">pcp352933pcs:GitLearning WXM$ git log\ncommit d90715179d20e10c5d88fc8d8a58972605fb38c0\nAuthor: Jun &lt;wuxiaomin98@hotmail.com&gt;\nDate: Wed Mar 30 16:32:28 2016 -0500\n\nFirst time writing readme file\npcp352933pcs:GitLearning WXM$ cat READMEFILE.txt\nThis is a readme file.\n<\/pre>\n<p>However, if one day we find that the lines we added are useful, could we go further and get it back? Yes, we can! If the terminal is not closed, we need to find the commit number which the version is. For example, the commit number for Love making changes version is 67713e5af45b67aa2628b12a73d4b493a16de159. Then we can use the <code>git reset --hard<\/code> command with the commit id following it. Note that we can use the first few numbers of the commit id in most case.<\/p>\n<pre class=\"brush:bash\">pcp352933pcs:GitLearning WXM$ git reset --hard 67713e5a\nHEAD is now at 67713e5 Love making changes\npcp352933pcs:GitLearning WXM$ cat READMEFILE.txt \nThis is a readme file.\nBad words for others.\nI made changes again:)\nI love changing things.\n<\/pre>\n<p>You see, it&#8217;s back. However, make sure you really want to go back and force. In some cases, if you don&#8217;t know the commit id, you won&#8217;t come back to the newest version.<\/p>\n<p>In some cases, that you really want to come back to the newest version. Then <code>git reflow<\/code> could be useful for you, which will track every command you&#8217;ve made. Run the command and you&#8217;ll get something magic.<\/p>\n<pre class=\"brush:bash\">pcp352933pcs:GitLearning WXM$ git reflog\nd907151 HEAD@{0}: reset: moving to HEAD^^^\n67713e5 HEAD@{1}: reset: moving to 67713e5a\nd907151 HEAD@{2}: reset: moving to HEAD~2\n47640c1 HEAD@{3}: reset: moving to HEAD^\n67713e5 HEAD@{4}: commit: Love making changes\n47640c1 HEAD@{5}: commit: Made changes again\n1f50e80 HEAD@{6}: commit: Add bad words\nd907151 HEAD@{7}: commit: First time writing readme file\n<\/pre>\n<p>Here we have all the commit number to each commit and each reset\/undo operation. So you don&#8217;t need to worry about where you&#8217;re now.<\/p>\n<p>To make it more clear to understand, we can use the following figure to show how it work. The HEAD works as a pointer to point to specific version. For example, if HEAD is pointer to the last version. Then after using the reset command, we can go back the initial version.<\/p>\n<p><figure id=\"attachment_35628\" aria-describedby=\"caption-attachment-35628\" style=\"width: 403px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/git-undo.jpg\" rel=\"attachment wp-att-35628\"><img decoding=\"async\" class=\"wp-image-35628 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/git-undo.jpg\" alt=\"git undo\" width=\"403\" height=\"304\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/git-undo.jpg 403w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/git-undo-300x226.jpg 300w\" sizes=\"(max-width: 403px) 100vw, 403px\" \/><\/a><figcaption id=\"caption-attachment-35628\" class=\"wp-caption-text\">Git head operation version 4<\/figcaption><\/figure><br \/>\n<figure id=\"attachment_35627\" aria-describedby=\"caption-attachment-35627\" style=\"width: 403px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/git-undo1.jpg\" rel=\"attachment wp-att-35627\"><img decoding=\"async\" class=\"wp-image-35627 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/git-undo1.jpg\" alt=\"git undo1\" width=\"403\" height=\"304\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/git-undo1.jpg 403w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/03\/git-undo1-300x226.jpg 300w\" sizes=\"(max-width: 403px) 100vw, 403px\" \/><\/a><figcaption id=\"caption-attachment-35627\" class=\"wp-caption-text\">Git undo operation to version 1<\/figcaption><\/figure><\/p>\n<h2>3. Conclusion<\/h2>\n<p>Git undo operation makes it quite easy for us to go back and force to different versions. If you get familiar with it, then it could be very powerful. However, please make sure that you know where you go to when you perform the undo operation. If not, you can make another branch to operate it, which will make your code more safe.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction Every human being&nbsp;may make mistakes, especially the Software developers:) When we&#8217;re writing code, it&#8217;s a process of how we&#8217;re thinking and how we solve specific problems. In real life, it could be a disaster if we make some irrecoverable mistakes. However, this will not happen in writing code for the developers, especially with &hellip;<\/p>\n","protected":false},"author":73,"featured_media":27377,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1353],"tags":[1426],"class_list":["post-35604","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-git","tag-git-undo"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Git Undo Commit Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"1. Introduction Every human being&nbsp;may make mistakes, especially the Software developers:) When we&#039;re writing code, it&#039;s a process of how we&#039;re\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Git Undo Commit Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"1. Introduction Every human being&nbsp;may make mistakes, especially the Software developers:) When we&#039;re writing code, it&#039;s a process of how we&#039;re\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2016-04-01T13:09:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-04-23T11:54:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/git-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Jun Wu\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jun Wu\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/\"},\"author\":{\"name\":\"Jun Wu\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6593091dba631ca0f41c4ba4e7c97678\"},\"headline\":\"Git Undo Commit Example\",\"datePublished\":\"2016-04-01T13:09:41+00:00\",\"dateModified\":\"2019-04-23T11:54:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/\"},\"wordCount\":1752,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/git-logo.jpg\",\"keywords\":[\"Git undo\"],\"articleSection\":[\"Git\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/\",\"name\":\"Git Undo Commit Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/git-logo.jpg\",\"datePublished\":\"2016-04-01T13:09:41+00:00\",\"dateModified\":\"2019-04-23T11:54:28+00:00\",\"description\":\"1. Introduction Every human being&nbsp;may make mistakes, especially the Software developers:) When we're writing code, it's a process of how we're\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/git-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/git-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Software Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/software-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Git\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/software-development\/git\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Git Undo Commit Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6593091dba631ca0f41c4ba4e7c97678\",\"name\":\"Jun Wu\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/Jun-Wu-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/Jun-Wu-96x96.jpg\",\"caption\":\"Jun Wu\"},\"description\":\"Jun (Steven) Wu is a current Master student in Computer Science &amp; Engineering department of University of Nebraska Lincoln (Lincoln, NE, USA). His current interests focus on Programming Languages (Java, Python), Relational Database (MySQL), NoSQL Database (Apache Cassandra, MongoDB), and Computer Networks.\",\"sameAs\":[\"https:\/\/wuxiaomin98.wordpress.com\/\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/jun-wu\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Git Undo Commit Example - Java Code Geeks","description":"1. Introduction Every human being&nbsp;may make mistakes, especially the Software developers:) When we're writing code, it's a process of how we're","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/","og_locale":"en_US","og_type":"article","og_title":"Git Undo Commit Example - Java Code Geeks","og_description":"1. Introduction Every human being&nbsp;may make mistakes, especially the Software developers:) When we're writing code, it's a process of how we're","og_url":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2016-04-01T13:09:41+00:00","article_modified_time":"2019-04-23T11:54:28+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/git-logo.jpg","type":"image\/jpeg"}],"author":"Jun Wu","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Jun Wu","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/"},"author":{"name":"Jun Wu","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6593091dba631ca0f41c4ba4e7c97678"},"headline":"Git Undo Commit Example","datePublished":"2016-04-01T13:09:41+00:00","dateModified":"2019-04-23T11:54:28+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/"},"wordCount":1752,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/git-logo.jpg","keywords":["Git undo"],"articleSection":["Git"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/","url":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/","name":"Git Undo Commit Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/git-logo.jpg","datePublished":"2016-04-01T13:09:41+00:00","dateModified":"2019-04-23T11:54:28+00:00","description":"1. Introduction Every human being&nbsp;may make mistakes, especially the Software developers:) When we're writing code, it's a process of how we're","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/git-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/git-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-undo-commit-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Software Development","item":"https:\/\/examples.javacodegeeks.com\/category\/software-development\/"},{"@type":"ListItem","position":3,"name":"Git","item":"https:\/\/examples.javacodegeeks.com\/category\/software-development\/git\/"},{"@type":"ListItem","position":4,"name":"Git Undo Commit Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6593091dba631ca0f41c4ba4e7c97678","name":"Jun Wu","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/Jun-Wu-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/Jun-Wu-96x96.jpg","caption":"Jun Wu"},"description":"Jun (Steven) Wu is a current Master student in Computer Science &amp; Engineering department of University of Nebraska Lincoln (Lincoln, NE, USA). His current interests focus on Programming Languages (Java, Python), Relational Database (MySQL), NoSQL Database (Apache Cassandra, MongoDB), and Computer Networks.","sameAs":["https:\/\/wuxiaomin98.wordpress.com\/"],"url":"https:\/\/examples.javacodegeeks.com\/author\/jun-wu\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/35604","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/73"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=35604"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/35604\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/27377"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=35604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=35604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=35604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}