{"id":357,"date":"2022-05-17T08:34:01","date_gmt":"2022-05-17T00:34:01","guid":{"rendered":"http:\/\/madapapa.com\/wordpress\/?p=357"},"modified":"2022-06-18T20:23:15","modified_gmt":"2022-06-18T12:23:15","slug":"git","status":"publish","type":"post","link":"http:\/\/madapapa.com\/wordpress\/?p=357","title":{"rendered":"Git"},"content":{"rendered":"<h2><a id=\"%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u57fa\u672c\u64cd\u4f5c<\/h2>\n<p>\u7ed1\u5b9a\u7528\u6237\u540d\u548c\u90ae\u7bb1\u5730\u5740<\/p>\n<pre><code class=\"language-plain_text\">(venv) 22-05-17\/Users\/XXXXX\/study\/watchlist~%&gt;git --version\ngit version 2.30.1 (Apple Git-130)\n(venv) 22-05-17\/Users\/xxxxx\/study\/watchlist~%&gt;git config --global user.nam\ne &quot;xxxxxxx&quot;\n(venv) 22-05-17\/Users\/xxxxx\/study\/watchlist~%&gt;git config --global user.ema\nil &quot;xxxxxx@outlook.com&quot;\n<\/code><\/pre>\n<p>\u67e5\u770b\u672c\u5730\u5206\u652f<\/p>\n<pre><code class=\"language-plain_text\">test~%&gt;git branch -vv\n* flask     71a338f this is a test of microblog project\n  flasktest 71a338f this is a test of microblog project\n  master    71a338f this is a test of microblog project\n<\/code><\/pre>\n<p>\u67e5\u770b\u8fdc\u7a0b\u5206\u652f<\/p>\n<pre><code class=\"language-plain_text\">watchlist~%&gt;git branch -r\n  origin\/master\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"http:\/\/madapapa.com\/wordpress\/wp-content\/uploads\/2022\/05\/16527921407739.jpg\" alt=\"\" \/><\/p>\n<p>\u5220\u9664\u672c\u5730\u5206\u652f<\/p>\n<pre><code class=\"language-plain_text\">microblog\/test~%&gt;git branch -d flasktest\nDeleted branch flasktest (was 71a338f).\n<\/code><\/pre>\n<p>\u67e5\u770b\u914d\u7f6e\u5217\u8868<\/p>\n<pre><code class=\"language-plain_text\">test~%&gt;git config --list\n<\/code><\/pre>\n<pre><code class=\"language-plain_text\">remote.origin.url=git@github.com:XXXXXX\/flasktest.git\nremote.origin.fetch=+refs\/heads\/*:refs\/remotes\/origin\/*\nbranch.master.remote=origin\n<\/code><\/pre>\n<h2><a id=\"push%E4%B8%8Epull\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>push\u4e0epull<\/h2>\n<h3><a id=\"push%E5%91%BD%E4%BB%A4\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>push\u547d\u4ee4<\/h3>\n<p>push\u547d\u4ee4\u7528\u6765\u5c06\u8fdc\u7a0b\u5206\u652f\u5185\u5bb9\uff0c\u62c9\u53d6\u5230\u672c\u5730\u5206\u652f\u4e0a\uff0c\u5f53\u8fdc\u7a0b\u5206\u652f\u548c\u672c\u5730\u5206\u652f\u540d\u79f0\u4e00\u81f4\u65f6\uff0c\u53ef\u4ee5\u7701\u7565\u672c\u5730\u5206\u652f\u540d\u79f0\uff0cpush\u547d\u4ee4\u4e2d\u7684origin\u4f1a\u8ba9\u4eba\u5f88\u7591\u60d1<\/p>\n<p>pull\u547d\u4ee4<\/p>\n<p><a href=\"https:\/\/blog.51cto.com\/u_15262460\/2883040\">push\u4e0epull\u547d\u4ee4\u53c2\u8003<\/a><\/p>\n<h2><a id=\"%E5%BB%BA%E7%AB%8B%E6%88%96%E5%88%A0%E9%99%A4%E6%9C%AC%E5%9C%B0%E5%BA%93%E4%B8%8E%E8%BF%9C%E7%A8%8B%E5%BA%93%E7%9A%84%E7%BB%91%E5%AE%9A\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u5efa\u7acb\u6216\u5220\u9664\u672c\u5730\u5e93\u4e0e\u8fdc\u7a0b\u5e93\u7684\u7ed1\u5b9a<\/h2>\n<p>\u5efa\u7acb\u672c\u5730\u5e93\u4e0e\u8fdc\u7a0b\u5e93\u7684\u7ed1\u5b9a\u5173\u7cfb\uff0c\u548c\u8fdc\u7a0b\u5e93\u8fdb\u884c\u7ed1\u5b9a\u65f6\uff0c\u9700\u8981\u7ed9\u8fdc\u7a0b\u5e93\u4e00\u4e2a\u540d\u5b57\uff0c\u4e00\u822c\u6765\u8bf4origin\u5c31\u662f\u9ed8\u8ba4\u7684\u540d\u79f0<\/p>\n<pre><code class=\"language-plain_text\">xxx\/flasky\/watchlist~%&gt;git remote add origin git@github.com:xxx\/watchlist.git\n<\/code><\/pre>\n<p>\u5220\u9664\u672c\u5730\u5e93\u548c\u8fdc\u7a0b\u5e93\u7684\u7ed1\u5b9a\uff0c\u6ce8\u610f\u8fd9\u91cc\u53ea\u662f\u5220\u9664\u4e86\u672c\u5730\u5e93\u4e0e\u8fdc\u7a0b\u5e93\u4e4b\u95f4\u7684\u6620\u5c04\u5173\u7cfb\uff0c\u5e76\u6ca1\u6709\u771f\u7684\u5220\u9664\u4efb\u4f55\u7269\u7406\u5185\u5bb9\u3002<\/p>\n<pre><code class=\"language-plain_text\">xxx\/flasky\/watchlist\/watchlist~%&gt;git remote rm origin\nxxx\/flasky\/watchlist\/watchlist~%&gt;git remote -v\n<\/code><\/pre>\n<p>\u5982\u679c\u6709\u7ed1\u5b9a\u7684\u8fdc\u7a0b\u5e93\uff0c\u547d\u4ee4\u201cgit remote -v\u201d\u4f1a\u663e\u793a\u5982\u4e0b<br \/>\n<img decoding=\"async\" src=\"http:\/\/madapapa.com\/wordpress\/wp-content\/uploads\/2022\/06\/16554664910496.jpg\" alt=\"\" \/><br \/>\n\u73b0\u5728\u56e0\u4e3a\u6211\u4f7f\u7528git remote rm origin\u547d\u4ee4\u5220\u9664\u4e86\u7ed1\u5b9a\u5173\u7cfb\uff0c\u5219git remote -v\u4ec0\u4e48\u90fd\u4e0d\u4f1a\u663e\u793a\uff0c\u56e0\u4e3alinux\u7684\u6700\u5927\u7406\u5ff5\u5c31\u662f\uff0c\u201c\u6ca1\u6709\u6d88\u606f\u5c31\u662f\u597d\u6d88\u606f\u201d\ud83d\ude0a<\/p>\n<h2><a id=\"fatal-refusing-to-merge-unrealated-histories\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>fatal: refusing to merge unrealated histories<\/h2>\n<pre><code class=\"language-plain_text\">xxxx\/flasky\/watchlist~%&gt;git pull origin master\nFrom https:\/\/github.com\/xxxx\/watchlist\n * branch            master     -&gt; FETCH_HEAD\nfatal: refusing to merge unrelated histories\n<\/code><\/pre>\n<p>The \u201cfatal: refusing to merge unrelated histories\u201d Git error occurs when two unrelated projects are merged, and two projects are unaware of each other existence and having mismatch commit histories.<br \/>\n<img decoding=\"async\" src=\"http:\/\/madapapa.com\/wordpress\/wp-content\/uploads\/2022\/06\/16555396081032.jpg\" alt=\"\" \/><br \/>\nTo provide a little background .git directory, which is usually hidden, contains all the changes or \u201ccommits\u201d of the repo that gets tracked. Rewriting the repository history is possible, but it\u2019s generally not the typical use case. Git is used for version control, which means to track the history of the file.<\/p>\n<p>Use Cases that lead to git fatal: refusing to merge unrelated histories<\/p>\n<p>If you have cloned a repository and, for some reason, the .git folder is corrupted or deleted. Since git will be unaware of your local history, any action you perform like git pull or git push to remote repository will throw this error as there is no tracking information for the current branch.<br \/>\nYou have created a new repository, made few commits to it, and now try to pull a remote repository that already has its own commits. Git will throw an error here since it is unaware of how these two projects and commits are related.<\/p>\n<h3><a id=\"the-solution-to-refusing-to-merge-unrelated-histories\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>The solution to Refusing to merge unrelated histories<\/h3>\n<p>The error started occurring from git version 2.9.0 release notes and above. To solve this issue &#8211;allow-unrelated-histories flag when pulling the data from remote repository.<\/p>\n<p><a href=\"https:\/\/itsmycode.com\/fatal-refusing-to-merge-unrelated-histories-solved\/\">\u89e3\u51b3unrelated histories\u95ee\u9898\u53c2\u8003<\/a><\/p>\n<h2><a id=\"%E5%85%A8%E6%B5%81%E7%A8%8B%E6%A6%82%E8%A6%81\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u5168\u6d41\u7a0b\u6982\u8981<\/h2>\n<ul>\n<li>1 \u7ed1\u5b9a\u7528\u6237\u540d\u548c\u90ae\u7bb1\u5730\u5740(SSH\u6307\u7eb9\u4e5f\u63d0\u524d\u5173\u8054\u597d)<\/li>\n<li>2 mkdir watchlist<\/li>\n<li>3 \u521d\u59cb\u5316\u672c\u5730\u5e93<\/li>\n<\/ul>\n<pre><code class=\"language-plain_text\">xxxx\/flasky\/watchlist~%&gt;git init\nInitialized empty Git repository in \/Users\/xxxx\/Study\/flasky\/watchlist\/.git\/\n<\/code><\/pre>\n<ul>\n<li>4 \u7ed1\u5b9a\u672c\u5730\u5e93\u4e0e\u8fdc\u7a0b\u5e93<\/li>\n<\/ul>\n<pre><code class=\"language-plain_text\">flasky\/watchlist~%&gt;git remote add origin git@github.com:madapapa\/watchlist.git\n<\/code><\/pre>\n<ul>\n<li>5 \u67e5\u770b\u8fdc\u7a0b\u5e93<\/li>\n<\/ul>\n<pre><code class=\"language-plain_text\">xxxx\/flasky\/watchlist~%&gt;git remote -v\norigin\tgit@github.com:madapapa\/watchlist.git (fetch)\norigin\tgit@github.com:madapapa\/watchlist.git (push)\n<\/code><\/pre>\n<ul>\n<li>6 \u540c\u6b65\u8fdc\u7a0b\u5e93\u5185\u5bb9\uff0c\u5ffd\u7565unrelated histories\u95ee\u9898<\/li>\n<\/ul>\n<pre><code class=\"language-plain_text\">xxxx\/flasky\/watchlist~%&gt;git pull origin master --allow-unrelated-histories\nremote: Enumerating objects: 49, done.\nremote: Counting objects: 100% (49\/49), done.\nremote: Compressing objects: 100% (33\/33), done.\nremote: Total 49 (delta 16), reused 38 (delta 10), pack-reused 0\nUnpacking objects: 100% (49\/49), 438.70 KiB | 477.00 KiB\/s, done.\nFrom github.com:madapapa\/watchlist\n * branch            master     -&gt; FETCH_HEAD\n * [new branch]      master     -&gt; origin\/master\n<\/code><\/pre>\n<ul>\n<li>\n<p>7 \u6211\u6ca1\u6709\u65b0\u5efagitignore\u6587\u4ef6<\/p>\n<\/li>\n<li>\n<p>8 \u5728\u672c\u5730\u4fee\u6539\u6587\u4ef6\u540e\uff0c\u8fdb\u884c\u63d0\u4ea4\u5de5\u4f5c<\/p>\n<\/li>\n<\/ul>\n<blockquote>\n<p>\u3010\u6ce8\u610f\u3011\u8fd9\u91cc\u7684push\u547d\u4ee4\u5728\u7b2c\u4e00\u6b21\u4f7f\u7528\u65f6\uff0c\u4e00\u822c\u5efa\u8bae\u9644\u5e26-u\u53c2\u6570,\u8fd9\u6837Git\u4e0d\u4ec5\u4f1a\u628a\u672c\u5730master\u5206\u652f\u7684\u5185\u5bb9\u66f4\u65b0\u5230\u8fdc\u7a0b\u65b0\u5efa\u7684master\u5206\u652f\u4e0a\uff0c\u8fd8\u4f1a\u628a\u672c\u5730master\u548c\u8fdc\u7a0b\u7684master\u5173\u8054\u8d77\u6765\uff0c\u5728\u4ee5\u540e\u7684\u63a8\u9001\u548c\u62c9\u53d6\u65f6\u5c31\u53ef\u4ee5\u7b80\u5316\u547d\u4ee4\uff08\u4e0d\u9700\u8981\u5e26-u\u53c2\u6570\uff0c\u76f4\u63a5git push\u5373\u53ef\uff09\u3002<\/p>\n<\/blockquote>\n<p><img decoding=\"async\" src=\"http:\/\/madapapa.com\/wordpress\/wp-content\/uploads\/2022\/06\/16555242954456.jpg\" alt=\"\" \/><\/p>\n<p><a href=\"http:\/\/igmas.users.sgg.whu.edu.cn\/group\/blog\/19\">git\u5e38\u7528\u547d\u4ee4<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u672c\u64cd\u4f5c \u7ed1\u5b9a\u7528\u6237\u540d\u548c\u90ae\u7bb1\u5730\u5740 (venv) 22-05-17\/Users\/XXXXX\/study\/watchlist~%&gt;git &#8211;version git version 2.30.1 (Apple Git-130) (venv) 22-05-17\/Users\/xxxxx\/study\/watchlist~%&gt;git config &#8211;global user.nam e &quot;xxxxxxx&quot; (venv) 22-05-17\/Users\/xxxxx\/study\/watchlist~%&gt;git config &#8211;global user.ema il &quot;xxxxxx@outlook.com&quot; \u67e5\u770b\u672c\u5730\u5206\u652f test~%&gt;git branch -vv * flask 71a338f this is a test of microblog project flasktest 71a338f this is a test of microblog project master 71a338f this is a test of microblog &hellip; <a href=\"http:\/\/madapapa.com\/wordpress\/?p=357\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Git<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[44,5],"tags":[],"class_list":["post-357","post","type-post","status-publish","format-standard","hentry","category-flask","category-linux"],"_links":{"self":[{"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=357"}],"version-history":[{"count":6,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/357\/revisions"}],"predecessor-version":[{"id":392,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/357\/revisions\/392"}],"wp:attachment":[{"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=357"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}