{"id":362,"date":"2023-08-02T08:58:27","date_gmt":"2023-08-02T00:58:27","guid":{"rendered":"https:\/\/www.aqrboyblog.top\/?p=362"},"modified":"2024-09-08T12:52:05","modified_gmt":"2024-09-08T04:52:05","slug":"git%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4","status":"publish","type":"post","link":"https:\/\/www.aqrboyblog.top\/?p=362","title":{"rendered":"git\u547d\u4ee4"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>git init  \u521d\u59cb\u5316\r\ngit add .   \u6dfb\u52a0 \u6240\u6709\u5185\u5bb9 \u5230\u7f13\u5b58\u533a\r\ngit commit -m \u2018first commit\u2019 \u63d0\u4ea4\u6ce8\u91ca\r\ngit remote add origin git@github.com:\u5e10\u53f7\u540d\/\u4ed3\u5e93\u540d.git  \u6dfb\u52a0\u8fdc\u7a0bgit\u5e93\u5730\u5740\r\ngit pull origin master  \u62c9\u53d6\u4e3b\u5206\u652f\u5185\u5bb9\r\ngit push origin master # -f \u5f3a\u63a8\r\ngit clone git@github.com:git\u5e10\u53f7\u540d\/\u4ed3\u5e93\u540d.git   \u514b\u9686\u8fdc\u7a0bgit\u5e93\r\n\r\n\u62c9\u53d6 \u67d0\u6b21\u63d0\u4ea4\u5185\u5bb9 \u5230 \u5f53\u524d\u5206\u652f\r\ngit cherry-pick &lt;commitHash>\r\n\u5c06 feature \u5206\u652f\u7684\u6700\u8fd1\u4e00\u6b21\u63d0\u4ea4\uff0c\u8f6c\u79fb\u5230\u5f53\u524d\u5206\u652f\r\ngit cherry-pick feature\r\n\u5c06 A \u548c B \u4e24\u4e2a\u63d0\u4ea4\u5e94\u7528\u5230\u5f53\u524d\u5206\u652f\r\ngit cherry-pick &lt;HashA> &lt;HashB>\r\n\u53ef\u4ee5\u8f6c\u79fb\u4ece A \u5230 B \u7684\u6240\u6709\u63d0\u4ea4 \u63d0\u4ea4 A \u5fc5\u987b\u65e9\u4e8e\u63d0\u4ea4 B\uff0c\u5426\u5219\u547d\u4ee4\u5c06\u5931\u8d25\uff0c\u4f46\u4e0d\u4f1a\u62a5\u9519\u3002\u6ce8\u610f\uff0c\u4f7f\u7528\u4e0a\u9762\u7684\u547d\u4ee4\uff0c\u63d0\u4ea4 A \u5c06\u4e0d\u4f1a\u5305\u542b\u5728 Cherry pick \u4e2d\r\ngit cherry-pick A..B \r\n\u5982\u679c\u8981\u5305\u542b\u63d0\u4ea4 A\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684\u8bed\u6cd5\u3002\r\ngit cherry-pick A^..B\r\n\r\ngit checkout master \u5207\u5230\u4e3b\u5206\u652f\r\ngit fetch origin \u83b7\u53d6\u6700\u65b0\u53d8\u66f4\r\ngit checkout -b dev origin\/master \u57fa\u4e8e\u4e3b\u5206\u652f\u521b\u5efadev\u5206\u652f\r\ngit add . \u6dfb\u52a0\u5230\u7f13\u5b58\r\ngit commit -m \u2018xxx\u2019 \u63d0\u4ea4\u5230\u672c\u5730\u4ed3\u5e93\r\ngit fetch origin \u83b7\u53d6\u6700\u65b0\u53d8\u66f4\r\n\r\ngit status\r\n\r\ngit add \u6587\u4ef6\u540d \u5c06\u5de5\u4f5c\u533a\u7684\u67d0\u4e2a\u6587\u4ef6\u6dfb\u52a0\u5230\u6682\u5b58\u533a\r\ngit add . \u5c06\u5f53\u524d\u5de5\u4f5c\u533a\u7684\u6240\u6709\u6587\u4ef6\u90fd\u52a0\u5165\u6682\u5b58\u533a\r\ngit add -u \u6dfb\u52a0\u6240\u6709\u88abtracked\u6587\u4ef6\u4e2d\u88ab\u4fee\u6539\u6216\u5220\u9664\u7684\u6587\u4ef6\u4fe1\u606f\u5230\u6682\u5b58\u533a\uff0c\u4e0d\u5904\u7406untracked\u7684\u6587\u4ef6\r\ngit add -A \u6dfb\u52a0\u6240\u6709\u88abtracked\u6587\u4ef6\u4e2d\u88ab\u4fee\u6539\u6216\u5220\u9664\u7684\u6587\u4ef6\u4fe1\u606f\u5230\u6682\u5b58\u533a\uff0c\u5305\u62ecuntracked\u7684\u6587\u4ef6\r\ngit add -i \u8fdb\u5165\u4ea4\u4e92\u754c\u9762\u6a21\u5f0f\uff0c\u6309\u9700\u6dfb\u52a0\u6587\u4ef6\u5230\u7f13\u5b58\u533a\r\n\r\ngit commit -m \u201c\u63d0\u4ea4\u8bf4\u660e\u201d \u5c06\u6682\u5b58\u533a\u5185\u5bb9\u63d0\u4ea4\u5230\u672c\u5730\u4ed3\u5e93\r\ngit commit -a -m \u201c\u63d0\u4ea4\u8bf4\u660e\u201d \u8df3\u8fc7\u7f13\u5b58\u533a\u64cd\u4f5c\uff0c\u76f4\u63a5\u628a\u5de5\u4f5c\u533a\u5185\u5bb9\u63d0\u4ea4\u5230\u672c\u5730\u4ed3\u5e93\r\n\r\n6\u3001\u67e5\u770b\u5386\u53f2\u8bb0\u5f55\r\ngit log \u67e5\u770b\u6240\u6709commit\u8bb0\u5f55(SHA-A\u6821\u9a8c\u548c\uff0c\u4f5c\u8005\u540d\u79f0\uff0c\u90ae\u7bb1\uff0c\u63d0\u4ea4\u65f6\u95f4\uff0c\u63d0\u4ea4\u8bf4\u660e)\r\ngit log -p -\u6b21\u6570 \u67e5\u770b\u6700\u8fd1\u591a\u5c11\u6b21\u7684\u63d0\u4ea4\u8bb0\u5f55\r\ngit log --stat \u7b80\u7565\u663e\u793a\u6bcf\u6b21\u63d0\u4ea4\u7684\u5185\u5bb9\u66f4\u6539\r\ngit log --name-only \u4ec5\u663e\u793a\u5df2\u4fee\u6539\u7684\u6587\u4ef6\u6e05\u5355\r\ngit log --name-status \u663e\u793a\u65b0\u589e\uff0c\u4fee\u6539\uff0c\u5220\u9664\u7684\u6587\u4ef6\u6e05\u5355\r\ngit log --oneline \u8ba9\u63d0\u4ea4\u8bb0\u5f55\u4ee5\u7cbe\u7b80\u7684\u4e00\u884c\u8f93\u51fa\r\ngit log --graph --all --online \u56fe\u5f62\u5c55\u793a\u5206\u652f\u7684\u5408\u5e76\u5386\u53f2\r\ngit log --author=\u4f5c\u8005 \u67e5\u8be2\u4f5c\u8005\u7684\u63d0\u4ea4\u8bb0\u5f55(\u548cgrep\u540c\u65f6\u4f7f\u7528\u8981\u52a0\u4e00\u4e2a--all--match\u53c2\u6570)\r\ngit log --grep=\u8fc7\u6ee4\u4fe1\u606f \u5217\u51fa\u63d0\u4ea4\u4fe1\u606f\u4e2d\u5305\u542b\u8fc7\u6ee4\u4fe1\u606f\u7684\u63d0\u4ea4\u8bb0\u5f55\r\ngit log -S\u67e5\u8be2\u5185\u5bb9 \u548c--grep\u7c7b\u4f3c\uff0cS\u548c\u67e5\u8be2\u5185\u5bb9\u95f4\u6ca1\u6709\u7a7a\u683c\r\ngit log fileName \u67e5\u770b\u67d0\u6587\u4ef6\u7684\u4fee\u6539\u8bb0\u5f55\r\n\r\n\r\ngit reset HEAD^ \u6062\u590d\u6210\u4e0a\u6b21\u63d0\u4ea4\u7684\u7248\u672c\r\ngit reset HEAD^^ \u6062\u590d\u6210\u4e0a\u4e0a\u6b21\u63d0\u4ea4\u7684\u7248\u672c\uff0c\u5c31\u662f\u591a\u4e2a^\uff0c\u4ee5\u6b64\u7c7b\u63a8\u6216\u7528~\u6b21\u6570\r\ngit reflog\r\ngit reset --hard \u7248\u672c\u53f7\r\n--soft\uff1a\u53ea\u662f\u6539\u53d8HEAD\u6307\u9488\u6307\u5411\uff0c\u7f13\u5b58\u533a\u548c\u5de5\u4f5c\u533a\u4e0d\u53d8\uff1b\r\n--mixed\uff1a\u4fee\u6539HEAD\u6307\u9488\u6307\u5411\uff0c\u6682\u5b58\u533a\u5185\u5bb9\u4e22\u5931\uff0c\u5de5\u4f5c\u533a\u4e0d\u53d8\uff1b\r\n--hard\uff1a\u4fee\u6539HEAD\u6307\u9488\u6307\u5411\uff0c\u6682\u5b58\u533a\u5185\u5bb9\u4e22\u5931\uff0c\u5de5\u4f5c\u533a\u6062\u590d\u4ee5\u524d\u72b6\u6001\uff1b\r\n\u67e5\u770b\u5206\u652f\uff1agit branch -a\r\n\u5408\u5e76\u5206\u652f\uff1a\r\ngit merge dev #\u7528\u4e8e\u5408\u5e76\u6307\u5b9a\u5206\u652f\u5230\u5f53\u524d\u5206\u652f\r\ngit merge --no-ff -m \u201cmerge with no-ff\u201d dev #\u52a0\u4e0a--no-ff\u53c2\u6570\u5c31\u53ef\u4ee5\u7528\u666e\u901a\u6a21\u5f0f\u5408\u5e76\uff0c\u5408\u5e76\u540e\u7684\u5386\u53f2\u6709\u5206\u652f\uff0c\u80fd\u770b\u51fa\u6765\u66fe\u7ecf\u505a\u8fc7\u5408\u5e76\r\n\r\ngit\u76f8\u5173\u914d\u7f6e\r\ngit config --global user.name \u201c\u7528\u6237\u540d\u201d # \u8bbe\u7f6e\u7528\u6237\u540d\r\ngit config --global user.email \u201c\u7528\u6237\u90ae\u7bb1\u201d #\u8bbe\u7f6e\u90ae\u7bb1\r\ngit config --global user.name # \u67e5\u770b\u7528\u6237\u540d\u662f\u5426\u914d\u7f6e\u6210\u529f\r\ngit config --global user.email # \u67e5\u770b\u90ae\u7bb1\u662f\u5426\u914d\u7f6e\r\n\r\ngit config --global --list # \u67e5\u770b\u5168\u5c40\u8bbe\u7f6e\u76f8\u5173\u53c2\u6570\u5217\u8868\r\ngit config --local --list # \u67e5\u770b\u672c\u5730\u8bbe\u7f6e\u76f8\u5173\u53c2\u6570\u5217\u8868\r\ngit config --system --list # \u67e5\u770b\u7cfb\u7edf\u914d\u7f6e\u53c2\u6570\u5217\u8868\r\ngit config --list # \u67e5\u770b\u6240\u6709Git\u7684\u914d\u7f6e(\u5168\u5c40+\u672c\u5730+\u7cfb\u7edf)\r\ngit config --global color.ui true \/\/\u663e\u793agit\u76f8\u5173\u989c\u8272\r\n\r\n\u64a4\u6d88\u67d0\u6b21\u63d0\u4ea4\r\ngit revert HEAD # \u64a4\u9500\u6700\u8fd1\u7684\u4e00\u4e2a\u63d0\u4ea4\r\ngit revert \u7248\u672c\u53f7 # \u64a4\u9500\u67d0\u6b21commit<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-362","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/posts\/362","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=362"}],"version-history":[{"count":2,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/posts\/362\/revisions"}],"predecessor-version":[{"id":436,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/posts\/362\/revisions\/436"}],"wp:attachment":[{"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=362"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}