{"id":7981,"date":"2016-10-10T15:58:38","date_gmt":"2016-10-10T07:58:38","guid":{"rendered":"http:\/\/jpuyy.com\/?p=7981"},"modified":"2023-04-24T20:31:43","modified_gmt":"2023-04-24T12:31:43","slug":"git","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=7981","title":{"rendered":"git notes"},"content":{"rendered":"<p>level 6<\/p>\n<p>rebase<\/p>\n<p>git fetch\u53ea\u83b7\u53d6\uff0c\u5e76\u4e0d\u5408\u5e76<\/p>\n<p>\u672c\u5730\u4e0e\u8fdc\u7aef\u4f7f\u7528git rebase<br \/>\ngit rebase\u8fdb\u884c\u4e86\u4e09\u6b65\u64cd\u4f5c<\/p>\n<p>\u628a\u6240\u6709master\u7684\u6539\u53d8\u653e\u5230\u4e00\u4e2a\u4e34\u65f6\u533a\u57df\u91cc\u9762<\/p>\n<p>\u8fd0\u884c\u6240\u6709origin\/master\u7684\u63d0\u4ea4<\/p>\n<p>\u8fd0\u884c\u5728\u4e34\u65f6\u533a\u57df\u7684commits<\/p>\n<p>\u672c\u5730\u4e24\u4e2a\u5206\u652f\u95f4\u7684rebase\uff0cmaster\u548c&nbsp; develop\u5747\u6709\u63d0\u4ea4<\/p>\n<p>\u5728develop\u5206\u652f\u4e0b,<\/p>\n<p>git rebase master<\/p>\n<p>\u7136\u540e\u518dgit checkout master<\/p>\n<p>\u628adevelp\u5408\u5e76\u8fc7\u6765<\/p>\n<p>git merge develop<\/p>\n<p>conflicts\u672c\u5730master\u548c\u8fdc\u7aeforigin\/master\u90fd\u4fee\u6539\u4e86\u540c\u4e00\u4e2a\u6587\u4ef6\uff0c\u5e76\u5728\u672c\u5730\u63d0\u4ea4<\/p>\n<p>\u89e3\u51b3\u51b2\u7a81<\/p>\n<p>\u5728master\u4e0agit fetch<\/p>\n<p>\u7136\u540egit rebase\uff0c\u8fd9\u6837\u4fdd\u8bc1\u5728master\u4e0a\u6709\u6700\u65b0\u7684\u4ee3\u7801<\/p>\n<p>\u8fd9\u91cc\u4f1a\u63d0\u793a\u6709\u51b2\u7a81<\/p>\n<p>\u5f53\u89e3\u51b3\u4e86\u95ee\u9898\uff0c\u5219\u7528git rebase &#8211;continue<\/p>\n<p>level 7<\/p>\n<p>git log<br \/>\nsha hash<\/p>\n<p>git config &#8211;global color.ui true<\/p>\n<p>git log &#8211;pretty=oneline<\/p>\n<p>git log &#8211;oneline &#8211;stat<\/p>\n<p>\u5f53\u524d\u5206\u652f\u4e0e master \u7684\u533a\u522b<\/p>\n<pre>git log --oneline  ...master\n<\/pre>\n<p>git log -p \u67e5\u770b\u5177\u4f53\u7684\u6539\u53d8<\/p>\n<p>git diff&nbsp; == git diff HEAD<br \/>\ngit diff HEAD^<\/p>\n<p>git diff HEAD~5<br \/>\ngit diff HEAD^..HEAD<\/p>\n<p>git diff sha..sha<br \/>\ngit diff master develop<\/p>\n<p>\u5bf9\u4e8e\u5355\u4e2a\u6587\u4ef6\u4e00\u76f4\u4ee5\u6765\u7684\u53d8\u5316<br \/>\ngit blame index.html &#8211;date short<br \/>\ngit status \u770b\u5230\u6709\u4e0d\u60f3\u63d0\u4ea4\u7684\uff0c\u5219\u5728 .git\/info\/exclude \u628a\u6587\u4ef6\u8fc7\u6ee4\u6389<\/p>\n<p>.gitignore<br \/>\ngit \u5220\u9664\u6587\u4ef6<br \/>\ngit rm README.txt<br \/>\n\u5728 system \u4e2d\u4e0d\u4f1a\u88ab\u5220\u9664\uff0c\u4f46\u5728 git \u4e2d\u4f1a\u5220\u9664<br \/>\ngit rm &#8211;cached development.log<\/p>\n<p>mac \u6307\u5b9a merge \u5de5\u5177<\/p>\n<pre>git config --global merge.tool opendiff\ngit config --global <a href=\"http:\/\/alias.st\">alias.st<\/a> status \u6765\u8bbe\u7f6e status \u7684\u522b\u540d\n<\/pre>\n<div><\/div>\n<div><\/div>\n<p>level 4<\/p>\n<pre>git push rejected\n<\/pre>\n<p>\u9996\u5148git pull<\/p>\n<p>pull\u7684\u52a8\u505a\u7ec6\u5206<\/p>\n<p>git fetch\u5230origin\/master<\/p>\n<p>\u5c06origin\/master\u5408\u5e76\u5230\u672c\u5730&nbsp; master<\/p>\n<p>git merge origin\/master<\/p>\n<p>\u73b0\u5728\u518dpush<\/p>\n<p>conflict<\/p>\n<p>\u5fc5\u987b\u624b\u52a8\u89e3\u51b3<\/p>\n<div><\/div>\n<div><\/div>\n<p>level 1<\/p>\n<p>\u67e5\u770bstaged\u6587\u4ef6\u505a\u4e86\u54ea\u4e9b\u6539\u52a8<\/p>\n<p>git diff &#8211;staged<\/p>\n<p>\u5728\u63d0\u4ea4\u7684\u540c\u65f6\u8fdb\u884c\u6dfb\u52a0<\/p>\n<p>git commit -a -m &#8220;add index&#8221;<\/p>\n<p>\u5c06\u4fee\u6539\u7684\u6587\u4ef6\u6062\u590d<\/p>\n<p>git checkout &#8212; cats.html index.html<\/p>\n<div><\/div>\n<div><\/div>\n<div>level 2<\/p>\n<p>undo\u4e0a\u4e00\u6b21\u63d0\u4ea4\uff0c\u5e76\u5c06\u6539\u53d8\u653e\u5230 staging \u4e2d<\/p>\n<pre>git reset --soft HEAD^<\/pre>\n<p>\u53ea\u4fee\u6539\u4e0a\u4e00\u6b21\u7684\u63d0\u4ea4<\/p>\n<pre>git commit --amend -m \"New Message\"\n<\/pre>\n<p>undo \u4e0a\u4e00\u6b21\u7684\u63d0\u4ea4\u548c\u4fee\u6539\uff0c\u4f60\u7684\u4fee\u6539\u4f1a\u4e22\u5931<\/p>\n<pre>git reset --hard HEAD^<\/pre>\n<p>undo \u4e0a\u4e24\u6b21\u7684\u63d0\u4ea4\u548c\u4fee\u6539<\/p>\n<pre>git reset --hard HEAD^^<\/pre>\n<p>git reset HEAD ostrich.html<\/p>\n<p>\u67e5\u770b\u8fdc\u7aef\u7684 fetch \u53ca push\u5730\u5740<br \/>\ngit remote -v<\/p>\n<p>git remote add &lt;name&gt; &lt;address&gt;<\/p>\n<p>\u5220\u9664\u8fdc\u7aef repo<br \/>\ngit remote rm &lt;name&gt;<\/p>\n<p>git push -u origin master<\/p>\n<p>origin\u662f\u8fdc\u7aef repo \u7684\u540d\u5b57\uff0c master \u662f\u672c\u5730\u5206\u652f\u7684\u540d\u5b57<\/p>\n<\/div>\n<p>\u8bbe\u7f6e git config user<\/p>\n<pre>git config --global --edit\n#\u5168\u5c40\u914d\u7f6e\u5728 ~\/.gitconfig\n[user]\n    name = myusername\n    email = myusername@example.com\n\n\u5f53\u524d\u9879\u76ee\u914d\u7f6e\u5728\n.git\/config\n<\/pre>\n<p>\u60f3\u8981\u4fdd\u5b58\u4e00\u4e2a\u7a7a\u76ee\u5f55\u65f6\uff0c\u4e00\u822c\u6dfb\u52a0\u4e00\u4e2a\u7a7a\u6587\u4ef6.gitkeep\uff0c\u6bd4\u5982<\/p>\n<pre>secrets\/.gitkeep<\/pre>\n<p>macOS \u81ea\u52a8\u4fdd\u5b58\u5230 keychain<\/p>\n<pre>git config --global credential.helper osxkeychain\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>level 6 rebase git fetch\u53ea\u83b7\u53d6\uff0c\u5e76\u4e0d\u5408\u5e76 \u672c\u5730\u4e0e\u8fdc\u7aef\u4f7f\u7528git rebase git rebase\u8fdb\u884c\u4e86\u4e09\u6b65\u64cd\u4f5c \u628a\u6240\u6709master\u7684\u6539\u53d8\u653e\u5230\u4e00\u4e2a\u4e34\u65f6\u533a\u57df\u91cc\u9762 \u8fd0\u884c\u6240\u6709origin\/master\u7684\u63d0\u4ea4 \u8fd0\u884c\u5728\u4e34\u65f6\u533a\u57df\u7684commits \u672c\u5730\u4e24\u4e2a\u5206\u652f\u95f4\u7684rebase\uff0cmaster\u548c&nbsp; develop\u5747\u6709\u63d0\u4ea4 \u5728develop\u5206\u652f\u4e0b, git rebase master \u7136\u540e\u518dgit checkout master \u628adevelp\u5408\u5e76\u8fc7\u6765 git merge develop conflicts\u672c\u5730master\u548c\u8fdc\u7aeforigin\/master\u90fd\u4fee\u6539\u4e86\u540c\u4e00\u4e2a\u6587\u4ef6\uff0c\u5e76\u5728\u672c\u5730\u63d0\u4ea4 \u89e3\u51b3\u51b2\u7a81 \u5728master\u4e0agit fetch \u7136\u540egit rebase\uff0c\u8fd9\u6837\u4fdd\u8bc1\u5728master\u4e0a\u6709\u6700\u65b0\u7684\u4ee3\u7801 \u8fd9\u91cc\u4f1a\u63d0\u793a\u6709\u51b2\u7a81 \u5f53\u89e3\u51b3\u4e86\u95ee\u9898\uff0c\u5219\u7528git rebase &#8211;continue level 7 git log sha hash git config &#8211;global color.ui true git log &#8211;pretty=oneline git log &#8211;oneline &#8211;stat \u5f53\u524d\u5206\u652f\u4e0e master [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[168,8,171,39],"tags":[],"class_list":["post-7981","post","type-post","status-publish","format-standard","hentry","category-git","category-linux","category-macos","category-windows"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/7981","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7981"}],"version-history":[{"count":9,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/7981\/revisions"}],"predecessor-version":[{"id":9746,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/7981\/revisions\/9746"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7981"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7981"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7981"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}