{"id":922,"date":"2014-02-18T09:13:57","date_gmt":"2014-02-18T16:13:57","guid":{"rendered":"http:\/\/10kdev.net\/?p=922"},"modified":"2014-02-18T09:14:33","modified_gmt":"2014-02-18T16:14:33","slug":"git-staging-commandem-style","status":"publish","type":"post","link":"http:\/\/10kdev.net\/?p=922","title":{"rendered":"Git Staging Commandem Style"},"content":{"rendered":"<p>Staging in git is when you gather all the files you want \u00a0together, new, deleted, and unchanged &#8212; for a commit. \u00a0Once you commit them they are tracked as a commit with a message and a number, and then available to push to a central repository or where ever.<\/p>\n<p>I use the Tortoise Git GUI before I check in that can add\/stage in one commit action, then a separate push action. \u00a0 It&#8217;s because I need a graphical view of everything to eyeball before committing. \u00a0 The command line doesn&#8217;t really do it for me, especially if I have a large commit.<\/p>\n<p>But the question often comes up &#8211; <em><strong>how to stage manually in git<\/strong><strong>?<\/strong><\/em><\/p>\n<p>Here&#8217;s staging from the command line as I do it. \u00a0There are two methods that I know of right now.<\/p>\n<p>Navigate to your directory \u2013 I usually do this from \u201cparent pom\u201d directory so I can also maven build (for us java developers). \u00a0But somewhere in your local repository.<\/p>\n<p>Git&#8217;s \u201cadd\u201d is a bit dual-meaninged, like many git commands (merge for example which is different for branches versus clones). \u00a0It can mean &#8220;track me now and stage me&#8221; and it can mean &#8220;just stage me.&#8221; \u00a0This idea can be confusing &#8212; for instance with a new file why not &#8220;add&#8221; then &#8220;stage&#8221;? \u00a0But it&#8217;s all one execution in that case.<\/p>\n<p>Generally there are three states to &#8220;add&#8221; to a stage &#8212;<\/p>\n<ul>\n<li>you need to ADD any files to the stage that the repository does not know about that are new files.\u00a0 This will stage new files for commit.<\/li>\n<li>you need to ADD any files to the stage that git already knows about that have changes.\u00a0 This will stage changed files for commit.<\/li>\n<li>you need to ADD any files to the stage that git already knows about that have been deleted\u00a0.\u00a0 This will stage changed files for commit.<\/li>\n<\/ul>\n<p><strong>\u00a0Atomic Staging<\/strong><\/p>\n<p>First, I use \u201cgit status\u201d to see what\u2019s up.\u00a0 It lists everything changed and everything not tracked by the repository yet.<\/p>\n<p>What I usually do is this for the atomic method:<\/p>\n<p style=\"padding-left: 30px;\"><em>git status \/\/see what\u2019s up<\/em><\/p>\n<p style=\"padding-left: 30px;\"><em>git add &lt;new file&gt;<\/em><\/p>\n<p style=\"padding-left: 30px;\"><em>git add &lt;changed\/deleted file&gt;<\/em><\/p>\n<p>To unstage your changes use<\/p>\n<p style=\"padding-left: 30px;\"><em>git reset<\/em><\/p>\n<p>Recover a deleted file with<\/p>\n<p style=\"padding-left: 30px;\"><em>git checkout &#8212; &lt;file&gt;<\/em><\/p>\n<p>Be sure to use the full path from <em>git status<\/em><\/p>\n<p>After staging &#8211;&gt; commit, push.<\/p>\n<p><strong>Interactive Staging<\/strong><\/p>\n<p>You can also do this same thing interactively, which is what I use \u2013 git add interactive.<\/p>\n<p style=\"padding-left: 30px;\"><em>git add -i<\/em><\/p>\n<p>Command 4 let\u2019s you stage the new file by its number, and command 2 let\u2019s you stage a changed file by its number in a list that is presented to you in both cases.\u00a0 Command 3 let\u2019s you revert from stage very easily.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" alt=\"\" src=\"http:\/\/10kdev.net\/wp-content\/uploads\/2014\/02\/9cf098f7ec827609b55a456e6bd315fb.png\" width=\"557\" height=\"101\" \/><\/p>\n<p>You can check it out more in depth here:<\/p>\n<p><a href=\"http:\/\/git-scm.com\/book\/en\/Git-Tools-Interactive-Staging\">http:\/\/git-scm.com\/book\/en\/Git-Tools-Interactive-Staging<\/a><\/p>\n<p><a href=\"https:\/\/www.kernel.org\/pub\/software\/scm\/git\/docs\/git-add.html\">https:\/\/www.kernel.org\/pub\/software\/scm\/git\/docs\/git-add.html<\/a><\/p>\n<p>After staging &#8211;&gt; commit, push.<\/p>\n<p>I do not do blanket adds, like <em>git add &#8211;all<\/em>\u00a0because one never knows what file is NOT ignored that may pop up into the directory! Like a new .project file or some funky log file.<\/p>\n<hr \/>\n<p>I\u00a0*<b>always<\/b>* diff all files before I check in.<\/p>\n<p>I *<b>always<\/b>* eyeball my file collection before I stage.<\/p>\n<p>I *<b>always<\/b>* eyeball my commit before committing.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Staging in git is when you gather all the files you want \u00a0together, new, deleted, and unchanged &#8212; for a commit. \u00a0Once you commit them they are tracked as a commit with a message and a number, and then available to push to a central repository or where ever. I use the Tortoise Git GUI [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/922"}],"collection":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=922"}],"version-history":[{"count":12,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/922\/revisions"}],"predecessor-version":[{"id":934,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/922\/revisions\/934"}],"wp:attachment":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=922"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=922"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}