{"id":3630,"date":"2015-04-02T21:35:21","date_gmt":"2015-04-02T21:35:21","guid":{"rendered":"http:\/\/webninjataylor.com\/library\/?p=3630"},"modified":"2015-04-09T00:23:05","modified_gmt":"2015-04-09T00:23:05","slug":"git-git-immersion-notes","status":"publish","type":"post","link":"https:\/\/webninjataylor.com\/library\/git-git-immersion-notes\/","title":{"rendered":"Git: Git Immersion Notes"},"content":{"rendered":"<h2>Commands &amp; Notes<\/h2>\n<ul>\n<li><span class=\"code\">git add &lt;FILENAME&gt;<\/span> to add a single file or <span class=\"code\">git add .<\/span> to add all files to staging<\/li>\n<li><span class=\"code\">git commit -m \u201cMESSAGE\u201d<\/span> to commit in one step without entering editor mode<\/li>\n<li>Git history commands:\n<pre>git log\r\ngit log --pretty=oneline\r\ngit log --pretty=oneline --max-count=2\r\ngit log --pretty=oneline --since='5 minutes ago'\r\ngit log --pretty=oneline --until='5 minutes ago'\r\ngit log --pretty=oneline \u2014author=webninjataylor\r\ngit log --pretty=oneline \u2014all\r\ngit log --all --pretty=format:'%h %cd %s (%an)' --since='7 days ago\u2019\r\ngit log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short\r\n<\/pre>\n<\/li>\n<li><span class=\"code\">master<\/span> is the name of the default branch<\/li>\n<li>By checking out a branch by name, you go to the latest version of that branch<\/li>\n<li><span class=\"code\">git tag &lt;TAG-NAME&gt;<\/span> = Create a new tag<\/li>\n<li><span class=\"code\">git checkout &lt;TAG-NAME&gt;<\/span> = Check out a branch by tag<\/li>\n<li><span class=\"code\">git checkout &lt;BRANCH-NAME&gt;<\/span> = Check out a branch by branch name<\/li>\n<li><span class=\"code\">git tag<\/span> = Show all tags<\/li>\n<li>Push tags to GitHub&#8230;\n<pre>git push --tags<\/pre>\n<\/li>\n<li>View history in both directions from current spot&#8230;\n<pre>git hist master --all<\/pre>\n<\/li>\n<li><span class=\"code\">git checkout &lt;FILE&gt;<\/span> to revert changes<\/li>\n<li><span class=\"code\">git reset HEAD &lt;FILE&gt;<\/span>\u00a0to pull file out of staging<\/li>\n<li><span class=\"code\">git revert HEAD<\/span>\u00a0to revert commit just made<\/li>\n<li><span class=\"code\">git revert &lt;HASH&gt;<\/span> to revert to a specific commit<\/li>\n<li>Using the <span class=\"code\">hard<\/span> parameter indicates that the working directory should be updated to be consistent with the new branch head&#8230;\n<pre>git reset --hard &lt;HASH-OR-TAG&gt;<\/pre>\n<\/li>\n<li>git tag -d TAGNAME to remove unneeded tag names to aide garbage collection<\/li>\n<li>Amend previous commit before pushing with\n<pre>git commit --amend -m \u201cCOMMENT\u201d<\/pre>\n<\/li>\n<li><span class=\"code\">git mv &lt;FROM&gt; &lt;TO&gt;<\/span> to move a file<\/li>\n<li><span class=\"code\">cat .git\/HEAD<\/span> shows the branch HEAD is\u00a0currently referencing which is master by default<\/li>\n<li><span class=\"code\">git cat-file -t &lt;HASH&gt;<\/span> and\u00a0<span class=\"code\">git cat-file -p &lt;hash&gt;<\/span>\u00a0to view the contents of Git objects; which is all\u00a0blobs, trees, and commits<\/li>\n<li><span class=\"code\">git checkout -b\u00a0&lt;BRANCH-NAME&gt;<\/span> to create a new branch<\/li>\n<li>View log of commits on ALL branches, not just the current branch (assumes use of &#8220;hist&#8221; alias in .gitconfig)\n<pre>git hist --all<\/pre>\n<\/li>\n<li><span class=\"code\">git merge\u00a0master<\/span> when on a branch to merge master into it<\/li>\n<li><span class=\"code\">git merge\u00a0&lt;BRANCH-NAME&gt;<\/span>\u00a0when on master to merge the branch\u00a0into it<\/li>\n<li>Fix merge conflicts manually\u00a0&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD &#8230;\u00a0======= &#8230;\u00a0&gt;&gt;&gt;&gt;&gt;&gt;&gt; master<\/li>\n<li>Rebasing vs. merging (<span class=\"code\">git rebase master<\/span>)\n<ul>\n<li>The commit tree for the branch is\u00a0rewritten so that the master branch is a part of the commit history<\/li>\n<li>Don&#8217;t use for public repos<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>Config<\/h2>\n<p>You can add aliases to the\u00a0.gitconfig file<\/p>\n<pre>[alias]\r\n  co = checkout\r\n  ci = commit\r\n  st = status\r\n  br = branch\r\n  hist = log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short\r\n  type = cat-file -t\r\n  dump = cat-file -p\r\n<\/pre>\n<h2>Resources<\/h2>\n<ul>\n<li><a href=\"http:\/\/gitimmersion.com\/\" target=\"_blank\">Git Immersion<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Commands &amp; Notes git add &lt;FILENAME&gt; to add a single file or git add . to add all files to staging git commit -m \u201cMESSAGE\u201d to commit in one step without entering editor mode Git history commands: git log git log &#8211;pretty=oneline git log &#8211;pretty=oneline &#8211;max-count=2 git log &#8211;pretty=oneline &#8211;since=&#8217;5 minutes ago&#8217; git log &#8211;pretty=oneline [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[144],"tags":[2,22,157],"class_list":["post-3630","post","type-post","status-publish","format-standard","hentry","category-web-shots","tag-git","tag-terminal","tag-tools"],"_links":{"self":[{"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/posts\/3630","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/comments?post=3630"}],"version-history":[{"count":18,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/posts\/3630\/revisions"}],"predecessor-version":[{"id":3667,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/posts\/3630\/revisions\/3667"}],"wp:attachment":[{"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/media?parent=3630"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/categories?post=3630"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/tags?post=3630"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}