{"id":341,"date":"2018-04-06T20:23:23","date_gmt":"2018-04-06T12:23:23","guid":{"rendered":"http:\/\/www.liujh168.com\/?p=341"},"modified":"2018-04-06T23:11:38","modified_gmt":"2018-04-06T15:11:38","slug":"git_com","status":"publish","type":"post","link":"https:\/\/www.liujh168.com\/index.php\/2018\/04\/06\/git_com\/","title":{"rendered":"\u5e38\u7528git\u547d\u4ee4"},"content":{"rendered":"<p>        <strong>\u5e38\u7528\u547d\u4ee4\u901f\u67e5\uff1a<\/strong><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.liujh168.com\/wp-content\/uploads\/2018\/04\/git_flow.png\" alt=\"\" width=\"553\" height=\"462\" class=\"alignnone size-full wp-image-353\" srcset=\"https:\/\/www.liujh168.com\/wp-content\/uploads\/2018\/04\/git_flow.png 553w, https:\/\/www.liujh168.com\/wp-content\/uploads\/2018\/04\/git_flow-300x251.png 300w\" sizes=\"auto, (max-width: 553px) 85vw, 553px\" \/>        git init \/\/\u521d\u59cb\u5316\u672c\u5730git\u73af\u5883<br \/>\n        git clone XXX\/\/\u514b\u9686\u4e00\u4efd\u4ee3\u7801\u5230\u672c\u5730\u4ed3\u5e93<br \/>\n        git pull \/\/\u628a\u8fdc\u7a0b\u5e93\u7684\u4ee3\u7801\u66f4\u65b0\u5230\u5de5\u4f5c\u53f0<br \/>\n        git pull &#8211;rebase origin master \/\/\u5f3a\u5236\u628a\u8fdc\u7a0b\u5e93\u7684\u4ee3\u7801\u8ddf\u65b0\u5230\u5f53\u524d\u5206\u652f\u4e0a\u9762<br \/>\n        git fetch \/\/\u628a\u8fdc\u7a0b\u5e93\u7684\u4ee3\u7801\u66f4\u65b0\u5230\u672c\u5730\u5e93<br \/>\n        git add . \/\/\u628a\u672c\u5730\u7684\u4fee\u6539\u52a0\u5230stage\u4e2d<br \/>\n        git commit -m &#8216;comments here&#8217; \/\/\u628astage\u4e2d\u7684\u4fee\u6539\u63d0\u4ea4\u5230\u672c\u5730\u5e93<br \/>\n        git push \/\/\u628a\u672c\u5730\u5e93\u7684\u4fee\u6539\u63d0\u4ea4\u5230\u8fdc\u7a0b\u5e93\u4e2d<br \/>\n        <!--more--><\/p>\n<p>        git branch -r\/-a \/\/\u67e5\u770b\u8fdc\u7a0b\u5206\u652f\/\u5168\u90e8\u5206\u652f<br \/>\n        git checkout master\/branch \/\/\u5207\u6362\u5230\u67d0\u4e2a\u5206\u652f<br \/>\n        git checkout -b test \/\/\u65b0\u5efatest\u5206\u652f<br \/>\n        git checkout -d test \/\/\u5220\u9664test\u5206\u652f<br \/>\n        git merge master \/\/\u5047\u8bbe\u5f53\u524d\u5728test\u5206\u652f\u4e0a\u9762\uff0c\u628amaster\u5206\u652f\u4e0a\u7684\u4fee\u6539\u540c\u6b65\u5230test\u5206\u652f\u4e0a<br \/>\n        git merge tool \/\/\u8c03\u7528merge\u5de5\u5177<br \/>\n        git stash \/\/\u628a\u672a\u5b8c\u6210\u7684\u4fee\u6539\u7f13\u5b58\u5230\u6808\u5bb9\u5668\u4e2d<br \/>\n        git stash list \/\/\u67e5\u770b\u6240\u6709\u7684\u7f13\u5b58<br \/>\n        git stash pop \/\/\u6062\u590d\u672c\u5730\u5206\u652f\u5230\u7f13\u5b58\u72b6\u6001<br \/>\n        git blame someFile \/\/\u67e5\u770b\u67d0\u4e2a\u6587\u4ef6\u7684\u6bcf\u4e00\u884c\u7684\u4fee\u6539\u8bb0\u5f55\uff08\uff09\u8c01\u5728\u4ec0\u4e48\u65f6\u5019\u4fee\u6539\u7684\uff09<br \/>\n        git status \/\/\u67e5\u770b\u5f53\u524d\u5206\u652f\u6709\u54ea\u4e9b\u4fee\u6539<br \/>\n        git log \/\/\u67e5\u770b\u5f53\u524d\u5206\u652f\u4e0a\u9762\u7684\u65e5\u5fd7\u4fe1\u606f<br \/>\n        git diff \/\/\u67e5\u770b\u5f53\u524d\u6ca1\u6709add\u7684\u5185\u5bb9<br \/>\n        git diff &#8211;cache \/\/\u67e5\u770b\u5df2\u7ecfadd\u4f46\u662f\u6ca1\u6709commit\u7684\u5185\u5bb9<br \/>\n        git diff HEAD \/\/\u4e0a\u9762\u4e24\u4e2a\u5185\u5bb9\u7684\u5408\u5e76<br \/>\n        git reset &#8211;hard HEAD \/\/\u64a4\u9500\u672c\u5730\u4fee\u6539<br \/>\n        echo $HOME \/\/\u67e5\u770bgit config\u7684HOME\u8def\u5f84<br \/>\n        export $HOME=\/c\/gitconfig \/\/\u914d\u7f6egit config\u7684HOME\u8def\u5f84<\/p>\n<p> <strong>       \u56e2\u961f\u534f\u4f5cgit\u64cd\u4f5c\u6d41\u7a0b\uff1a<br \/>\n        \u514b\u9686\u4e00\u4e2a\u5168\u65b0\u7684\u9879\u76ee\uff0c\u5b8c\u6210\u65b0\u529f\u80fd\u5e76\u4e14\u63d0\u4ea4\uff1a<\/strong><br \/>\n        git clone XXX \/\/\u514b\u9686\u4ee3\u7801\u5e93<br \/>\n        git checkout -b test \/\/\u65b0\u5efa\u5206\u652f<br \/>\n        modify some files \/\/\u5b8c\u6210\u4fee\u6539<br \/>\n        git add . \/\/\u628a\u4fee\u6539\u52a0\u5165stage\u4e2d<br \/>\n        git commit -m &#8221; \/\/\u63d0\u4ea4\u4fee\u6539\u5230test\u5206\u652f<br \/>\n        review\u4ee3\u7801<br \/>\n        git checkout master \/\/\u5207\u6362\u5230master\u5206\u652f<br \/>\n        git pull \/\/\u66f4\u65b0\u4ee3\u7801<br \/>\n        git checkout test \/\/\u5207\u6362\u5230test\u5206\u652f<br \/>\n        git meger master \/\/\u628amaster\u5206\u652f\u7684\u4ee3\u7801merge\u5230test\u5206\u652f<br \/>\n        git push origin \u5206\u652f\u540d\/\/\u628atest\u5206\u652f\u7684\u4ee3\u7801push\u5230\u8fdc\u7a0b\u5e93<\/p>\n<p>        <strong>\u76ee\u524d\u6b63\u5728test\u5206\u652f\u4e0a\u9762\u5f00\u53d1\u67d0\u4e2a\u529f\u80fd\uff0c\u4f46\u662f\u6ca1\u6709\u5b8c\u6210\u3002\u7a81\u7136\u4e00\u4e2a\u7d27\u6025\u7684bug\u9700\u8981\u5904\u7406<\/strong><br \/>\n        git add .<br \/>\n        git stash<br \/>\n        git checkout bugFixBranch<br \/>\n        git pull &#8211;rebase origin master<br \/>\n        fix the bug<br \/>\n        git add .<br \/>\n        git commit -m &#8221;<br \/>\n        git push<br \/>\n        git checkout test<br \/>\n        git stash pop<br \/>\n        continue new feature&#8217;s development<\/p>\n<p>      \u8fd9\u91cc\u6709\u4e2a\u66f4\u8be6\u7ec6\u7684\uff1a<a href=\"https:\/\/blog.csdn.net\/afei__\/article\/details\/51476529\" rel=\"noopener\" target=\"_blank\"> Git\u5e38\u7528\u547d\u4ee4\uff0c\u5f88\u5168\u5f88\u8be6\u7ec6\u8bb2\u89e3\u7684\u4e5f\u4e0d\u9519 <\/a><\/p>\n<p><strong>\u4e00\u4e9b\u5c0f\u63d0\u793a\uff1a<\/strong><br \/>\n<strong>COMMIT RELATED CHANGES<\/strong><br \/>\nA commit should be a wrapper for related changes. For example, fixing two different bugs should produce two separate commits.Small commits make it easier for other developers to understand the changes and roll them back if something went wrong.With tools like the staging area and the ability to stage only parts of a file, Git makes it easy to create very granular commits.<br \/>\n<strong>COMMIT OFTEN<\/strong><br \/>\nCommitting often keeps your commits small and, again, helps you commit only related changes. Moreover, it allows you to share your code more frequently with others. That way it\u2018s easier for everyone to integrate changes regularly and avoid having merge conflicts. Having few large commits and sharing them rarely, in contrast, makes it hard to solve conflicts.<br \/>\n<strong>DON\u2018T COMMIT HALF-DONE WORK<\/strong><br \/>\nYou should only commit code when it\u2018s completed. This doesn\u2018t mean you have to complete a whole, large feature before committing. Quite the contrary: split the feature\u2018s implementation into logical chunks and remember to commit early and often. But don\u2018t commit just to have something in<br \/>\nthe repository before leaving the office at the end of the day. If you\u2018re tempted to commit just because you need a clean working copy (to check out a branch, pull in changes, etc.) consider using Git\u2018s \u00abStash\u00bb feature instead.<br \/>\n<strong>TEST CODE BEFORE YOU COMMIT<\/strong><br \/>\nResist the temptation to commit something that you \u00abthink\u00bb is completed. Test it thoroughly to make sure it really is completed and has no side effects (as far as one can tell).While committing half-baked things in your local repository only requires you to forgive yourself, having your code tested is even more important when it comes to pushing\/sharing your code with others.<br \/>\n<strong>WRITE GOOD COMMIT MESSAGES<\/strong><br \/>\nBegin your message with a short summary of your changes (up to 50 characters as a guideline). Separate it from the following body by including a blank line. The body of your message should provide detailed answers to the following questions:<br \/>\n\u203a What was the motivation for the change?<br \/>\n\u203a How does it differ from the previous implementation?<br \/>\nUse the imperative, present tense (\u00abchange\u00bb,not \u00abchanged\u00bb or \u00abchanges\u00bb) to be consistent with generated messages from commands like git merge.<br \/>\n<strong>VERSION CONTROL IS NOT A BACKUP SYSTEM<\/strong><br \/>\nHaving your files backed up on a remote server is a nice side effect of having a version control system. But you should not use your VCS like it was a backup system. When doing version control, you should pay attention to committing semantically (see \u00abrelated changes\u00bb) &#8211; you shouldn\u2018t just cram in files.<br \/>\n<strong>USE BRANCHES<\/strong><br \/>\nBranching is one of Git\u2018s most powerful features &#8211; and this is not by accident: quick and easy branching was a central requirement from day one.  ranches are the perfect tool to help you avoid mixing up different lines of development. You should use branches extensively in your development workflows: for new features, bug fixes, ideas\u2026<br \/>\n<strong>AGREE ON A WORKFLOW<\/strong><br \/>\nGit lets you pick from a lot of different workflows:<br \/>\nlong-running branches, topic branches, merge or rebase, git-flow\u2026 Which one you choose depends on a couple of factors:<br \/>\nyour project, your overall development and deployment workflows and (maybe most importantly) on your and your teammates\u2018 personal preferences. owever you choose to work, just make sure to agree on a common workflow that everyone follows.<br \/>\n<strong>HELP &#038; DOCUMENTATION<\/strong><br \/>\nGet help on the command line<br \/>\n$ git help <command><br \/>\nFREE ONLINE RESOURCES<br \/>\nhttp:\/\/www.git-tower.com\/learn<br \/>\nhttp:\/\/rogerdudler.github.io\/git-guide\/<br \/>\nhttp:\/\/www.git-scm.org\/ <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5e38\u7528\u547d\u4ee4\u901f\u67e5\uff1a git init \/\/\u521d\u59cb\u5316\u672c\u5730git\u73af\u5883 git clone XXX\/\/\u514b\u9686\u4e00\u4efd\u4ee3\u7801\u5230\u672c\u5730\u4ed3 &hellip; <a href=\"https:\/\/www.liujh168.com\/index.php\/2018\/04\/06\/git_com\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u5e38\u7528git\u547d\u4ee4\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,4,41],"tags":[16],"class_list":["post-341","post","type-post","status-publish","format-standard","hentry","category-remember","category-education","category-uncategorized","tag-it"],"_links":{"self":[{"href":"https:\/\/www.liujh168.com\/index.php\/wp-json\/wp\/v2\/posts\/341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.liujh168.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.liujh168.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.liujh168.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.liujh168.com\/index.php\/wp-json\/wp\/v2\/comments?post=341"}],"version-history":[{"count":14,"href":"https:\/\/www.liujh168.com\/index.php\/wp-json\/wp\/v2\/posts\/341\/revisions"}],"predecessor-version":[{"id":376,"href":"https:\/\/www.liujh168.com\/index.php\/wp-json\/wp\/v2\/posts\/341\/revisions\/376"}],"wp:attachment":[{"href":"https:\/\/www.liujh168.com\/index.php\/wp-json\/wp\/v2\/media?parent=341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.liujh168.com\/index.php\/wp-json\/wp\/v2\/categories?post=341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.liujh168.com\/index.php\/wp-json\/wp\/v2\/tags?post=341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}