{"id":203,"date":"2011-09-09T18:34:25","date_gmt":"2011-09-09T10:34:25","guid":{"rendered":"http:\/\/ykyi.net\/?p=203"},"modified":"2011-09-09T18:34:25","modified_gmt":"2011-09-09T10:34:25","slug":"knowledge-gained-from-learning-git","status":"publish","type":"post","link":"https:\/\/ykyi.net\/?p=203","title":{"rendered":"knowledge gained from learning git."},"content":{"rendered":"<p># If you inadvertently remove a file of your working copy. Don&#39;t worry. Git are good at recovering old versions of files, such as:<br \/>\n\t$git checkout HEAD &#8212; data<\/p>\n<p>&nbsp;<\/p>\n<p># show what the file looks like in a certain branch.<br \/>\n\t$git show branch_name:file_name<\/p>\n<p># In newer versions of Git, git diff &#8211;ours is a synonym for git diff HEAD, because it shows the differences between &quot;our&quot; version and the merged version. Similarly, git diff MERGE_HEAD can be written as git diff &#8211;theirs. You can use git diff &#8211;base to see the combined set of changes since the merge base, which would otherwise be rather awkwardly written as:<br \/>\n\tgit diff $(git merge-base HEAD MERGE_HEAD)<\/p>\n<p># While you are in the process of resolving a conflict, you can use some special git log options to help you figure out exactly where the changes came from and why. Try this:<br \/>\n\t$git log &#8211;merge &#8211;left-right -p<br \/>\n\t&#8211;merge shows only commits related to files that produced a conflict.<br \/>\n\t&#8211;left-right displays &lt; if the commit was from the &quot;left&quot; side of the merge(&quot;our version&quot;, the one you started with), or &gt; if the commit was from the &quot;right&quot; side of the merge(&quot;their&quot; version, the one you&#39;re merging in).<br \/>\n\t-p shows the commit message and the patch associated with each commit.<\/p>\n<p>If your repository were more complicated and several files had conflicts, you could also provide the exact file names you are interested in as a command line option, like this:<br \/>\n\t$git log &#8211;merge &#8211;left-right -p hello<\/p>\n<p># The -s option to git ls-files shows all the files with all stages. If you want to see only conflicted files, use the -u option instead.<\/p>\n<p># $ git checkout -m branch_name<br \/>\n\tIf possible or if specifically requested with the -m option, Git attempts to carry your local change into the new working directory by performing a merge operation between your local modifications and the target branch.<\/p>\n<p># $ git reset &#8211;hard ORIG_HEAD<br \/>\n\tIf you want to abort or discard the merge after it has finished(that is,after it has introduced a new merge commit), use the above command. Prior to beginning the merge operation, Git saves your original branch HEAD in the ORIG_HEAD ref for just this sort of purpose.<br \/>\n\tYou should be very careful here, though. If you did not start the merge with a clean working directory and index, you could geet in trouble and lose any uncommitted changes you have in your directory.<\/p>\n<p># Just show what the file looks like in a branch.<br \/>\n\t$ git show branch_name:file_name<\/p>\n<p># The command for manipulating remotes is git remote. This operation introduces a few new settings in the .git\/config file.<\/p>\n","protected":false},"excerpt":{"rendered":"<p># If you inadvertently remove a file of your working copy. Don&#39;t worry. Git are good at recovering old versions of files, such as: $git checkout HEAD &#8212; data &nbsp; # show what the file looks like in a certain branch. $git show branch_name:file_name # In newer versions of Git, git diff &#8211;ours is a &hellip; <a href=\"https:\/\/ykyi.net\/?p=203\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;knowledge gained from learning git.&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[36],"class_list":["post-203","post","type-post","status-publish","format-standard","hentry","category-tech_articles","tag-git"],"_links":{"self":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/posts\/203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=203"}],"version-history":[{"count":0,"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/posts\/203\/revisions"}],"wp:attachment":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}