{"id":1919,"date":"2014-06-07T09:14:46","date_gmt":"2014-06-07T16:14:46","guid":{"rendered":"http:\/\/www.wellgolly.com\/?p=1919"},"modified":"2020-05-06T14:18:25","modified_gmt":"2020-05-06T21:18:25","slug":"things-i-cant-remember-git","status":"publish","type":"post","link":"https:\/\/www.wellgolly.com\/?p=1919","title":{"rendered":"Things I can\u2019t remember &#8211; Git"},"content":{"rendered":"<p>In git you clone a project\u2014not checkout like in Subversion. You\u2019ll probably want to put it in a directory that has a name that is the same as the project (or related to the project name).<\/p>\n<p><pre><code class=\"preserve-code-formatting\">\n$ git clone git:\/\/github.com\/hubuser\/importantProject.git importantProject\n<\/code><\/pre><\/p>\n<p>If you are hosting your own git server, you\u2019ll probably use something like this.<\/p>\n<p><pre><code class=\"preserve-code-formatting\">\n$ git clone username@yourdomain.com:\/www\/importantProject\/ importantProject\n<\/code><\/pre><\/p>\n<p>Once you\u2019ve cloned the repository you\u2019ll have the exact same files and file structure as the original. You\u2019ll also be in the master branch.<\/p>\n<p><pre><code class=\"preserve-code-formatting\">\n$ git status\nOn branch master\nYour branch is up-to-date with &#039;origin\/master&#039;.\n\nnothing to commit, working directory clean\n<\/code><\/pre><\/p>\n<p>You\u2019ll also get a .git directory with the following files.<br \/>\n<pre><code class=\"preserve-code-formatting\">\n$ cd .git\ntotal 28\n-rw-r--r--&nbsp;&nbsp; 1 username&nbsp;&nbsp;staff&nbsp;&nbsp;&nbsp;&nbsp;23B Jun&nbsp;&nbsp;2 09:31 HEAD\ndrwxr-xr-x&nbsp;&nbsp; 2 username&nbsp;&nbsp;staff&nbsp;&nbsp;&nbsp;&nbsp;68B Jun&nbsp;&nbsp;2 09:31 branches\/\n-rw-r--r--&nbsp;&nbsp; 1 username&nbsp;&nbsp;staff&nbsp;&nbsp; 312B Jun&nbsp;&nbsp;2 09:31 config\n-rw-r--r--&nbsp;&nbsp; 1 username&nbsp;&nbsp;staff&nbsp;&nbsp;&nbsp;&nbsp;73B Jun&nbsp;&nbsp;2 09:31 description\ndrwxr-xr-x&nbsp;&nbsp;11 username&nbsp;&nbsp;staff&nbsp;&nbsp; 374B Jun&nbsp;&nbsp;2 09:31 hooks\/\n-rw-r--r--&nbsp;&nbsp; 1 username&nbsp;&nbsp;staff&nbsp;&nbsp; 8.8K Jun&nbsp;&nbsp;2 09:34 index\ndrwxr-xr-x&nbsp;&nbsp; 3 username&nbsp;&nbsp;staff&nbsp;&nbsp; 102B Jun&nbsp;&nbsp;2 09:31 info\/\ndrwxr-xr-x&nbsp;&nbsp; 4 username&nbsp;&nbsp;staff&nbsp;&nbsp; 136B Jun&nbsp;&nbsp;2 09:31 logs\/\ndrwxr-xr-x&nbsp;&nbsp; 4 username&nbsp;&nbsp;staff&nbsp;&nbsp; 136B Jun&nbsp;&nbsp;2 09:31 objects\/\n-rw-r--r--&nbsp;&nbsp; 1 username&nbsp;&nbsp;staff&nbsp;&nbsp; 107B Jun&nbsp;&nbsp;2 09:31 packed-refs\ndrwxr-xr-x&nbsp;&nbsp; 5 username&nbsp;&nbsp;staff&nbsp;&nbsp; 170B Jun&nbsp;&nbsp;2 09:31 refs\/\n<\/code><\/pre><\/p>\n<p>Now suppose I modify my robots.txt file.<\/p>\n<p><pre><code class=\"preserve-code-formatting\">\n$ git status\nOn branch master\nYour branch is up-to-date with &#039;origin\/master&#039;.\n\nChanges not staged for commit:\n&nbsp;&nbsp;(use &quot;git add &lt;file&gt;...&quot; to update what will be committed)\n&nbsp;&nbsp;(use &quot;git checkout -- &lt;file&gt;...&quot; to discard changes in working directory)\n\n&nbsp;&nbsp;modified:&nbsp;&nbsp; robots.txt\n\nno changes added to commit (use &quot;git add&quot; and\/or &quot;git commit -a&quot;)\n<\/code><\/pre><\/p>\n<p><pre><code class=\"preserve-code-formatting\">\n$ git diff\ndiff --git a\/robots.txt b\/robots.txt\nindex 90098a4..3aa5532 100755\n--- a\/robots.txt\n+++ b\/robots.txt\n@@ -1,3 +1,5 @@\n # robots.txt for http:\/\/www.rememo.info\/\n\n User-agent: *\n+Disallow: \/order\/\n+\n<\/code><\/pre><\/p>\n<p>Before we commit the file, we need to stage it. The status command above tells you how to to it.<br \/>\n<pre><code class=\"preserve-code-formatting\">\n$ git add robots.txt\n<\/code><\/pre><\/p>\n<p>We can see the staged changes with:<br \/>\n<pre><code class=\"preserve-code-formatting\">\n$ git diff --staged\ndiff --git a\/robots.txt b\/robots.txt\nindex 3aa5532..abd2889 100755\n--- a\/robots.txt\n+++ b\/robots.txt\n@@ -3,3 +3,4 @@\n User-agent: *\n+Disallow: \/order\/\n\n<\/code><\/pre><br \/>\nNow $git diff returns nothing because there are no unstaged changes.<\/p>\n<p>We can add and commit it in one command.<br \/>\n<pre><code class=\"preserve-code-formatting\">\ngit commit -a\n[master 4623ad2] Added a disallow\n 1 file changed, 2 insertions(+)\n<\/code><\/pre><\/p>\n<p>Alternatively, you can combine the commit with the message.<br \/>\n<pre><code class=\"preserve-code-formatting\">\ngit commit -a -m &quot;Added a disallow&quot;\n[master 4623ad2] Added a disallow\n 1 file changed, 2 insertions(+)\n<\/code><\/pre><\/p>\n<p>You can remove files from the repository by deleting them from your work area. They will show up in the unstaged area or you git status output. You can also use git rm to remove a file.<\/p>\n<p>Likewise you can rename a file with mv originalName newName and git will notice. Or you can use git mv originalName newName.<\/p>\n<p>You can view the commits that you have made with git log.<\/p>\n<p><pre><code class=\"preserve-code-formatting\">\n$ git log\ncommit 4623ad2cbe4163e2d013c7e53728023e4d7163e6\nAuthor: User Name &lt; username@WellGolly.com &gt;\nDate:&nbsp;&nbsp; Tue Jun 3 07:55:00 2014 -0700\n\n&nbsp;&nbsp;&nbsp;&nbsp;Added a disallow\n\ncommit 065b7362f9ad19d6e2fe69cde9629abf0beabb95\nAuthor: User Name &lt; username@WellGolly.com &gt;\nDate:&nbsp;&nbsp; Mon Feb 24 09:00:03 2014 -0800\n\n&nbsp;&nbsp;&nbsp;&nbsp;Changed site name and added blank line at end of files\n\ncommit 61277e4d12636044e9b873608c325470d98577e0\nAuthor: User Name &lt; username@WellGolly.com &gt;\nDate:&nbsp;&nbsp; Mon Feb 24 07:50:56 2014 -0800\n\n&nbsp;&nbsp;&nbsp;&nbsp;Started tracking changes to site with git.\n\n<\/code><\/pre><\/p>\n<p>If you want to see the changes that were made as well, use the -p option (page option) and the output will be piped into a pager where you can page through all the changes. Hit &#8216;q&#8217; to quit the pager.<\/p>\n<p>You can browse the commit messages with the &#8211;pretty option.<br \/>\n<pre><code class=\"preserve-code-formatting\">\n$git log --pretty=oneline\n4623ad2cbe4163e2d013c7e53728023e4d7163e6 Added a disallow\n065b7362f9ad19d6e2fe69cde9629abf0beabb95 Changed site name and added blank line at end of files\n61277e4d12636044e9b873608c325470d98577e0 Started tracking changes to site with git.\n<\/code><\/pre><\/p>\n<p>Once you have identified the commit you want more info on you can display the info with git show and the first few digits of the hash. Usually five digits is enough to uniquely identify the commit, but you can use all of them if you want.<br \/>\n<pre><code class=\"preserve-code-formatting\">\n$ git show --format=raw 4623a\ncommit 4623ad2cbe4163e2d013c7e53728023e4d7163e6\ntree 9c73a1afbfb9ec4930d3d4ac8d906e6ae4683df6\nparent 065b7362f9ad19d6e2fe69cde9629abf0beabb95\nauthor User Name &lt;username@WellGolly.com&gt; 1401807300 -0700\ncommitter User Name &lt;username@WellGolly.com&gt; 1401807300 -0700\n\n&nbsp;&nbsp;&nbsp;&nbsp;Commit message\n\ndiff --git a\/robots.txt b\/robots.txt\nindex 90098a4..3aa5532 100755\n--- a\/robots.txt\n+++ b\/robots.txt\n@@ -1,3 +1,5 @@\n # robots.txt for http:\/\/www.rememo.info\/\n\n User-agent: *\n+Disallow: \/order\/\n+\n<\/code><\/pre><\/p>\n<p>Often you might be looking for the last time a particular file was changed. &#8211;name-only gives the name of the file, the commit message, and the hash.<br \/>\n<pre><code class=\"preserve-code-formatting\">\n$ git log --name-only\ncommit 4623ad2cbe4163e2d013c7e53728023e4d7163e6\nAuthor: Gordon Miller &lt;developer@well.golly&gt;\nDate:&nbsp;&nbsp; Tue Jun 3 07:55:00 2014 -0700\n\n&nbsp;&nbsp;&nbsp;&nbsp;Added a disallow\n\nrobots.txt\n\ncommit 065b7362f9ad19d6e2fe69cde9629abf0beabb95\nAuthor: jscarry &lt;jscarry@learningfundamentals.com&gt;\nDate:&nbsp;&nbsp; Mon Feb 24 09:00:03 2014 -0800\n\n&nbsp;&nbsp;&nbsp;&nbsp;Started tracking changes to site with git.\n\nReminder\/README.txt\nReminder\/Reminder.inc\n:\n<\/code><\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In git you clone a project\u2014not checkout like in Subversion. You\u2019ll probably want to put it in a directory that has a name that is the same as the project (or related to the project name). $ git clone git:\/\/github.com\/hubuser\/importantProject.git importantProject If you are hosting your own git server, you\u2019ll probably use something like this. &hellip; <a href=\"https:\/\/www.wellgolly.com\/?p=1919\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Things I can\u2019t remember &#8211; Git<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1919","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1919","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1919"}],"version-history":[{"count":1,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1919\/revisions"}],"predecessor-version":[{"id":2931,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1919\/revisions\/2931"}],"wp:attachment":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1919"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1919"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1919"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}