{"id":220,"date":"2023-03-28T21:40:10","date_gmt":"2023-03-28T13:40:10","guid":{"rendered":"https:\/\/yajtech.synology.me\/wordpress\/?p=220"},"modified":"2023-04-11T17:51:15","modified_gmt":"2023-04-11T09:51:15","slug":"git-%e7%9a%84%e4%bd%bf%e7%94%a8-for-linux","status":"publish","type":"post","link":"https:\/\/www.yaj.com.tw\/wordpress\/?p=220","title":{"rendered":"Git \u7684\u4f7f\u7528 for Linux"},"content":{"rendered":"\n<p>\u5feb\u901f\u5f15\u5c0e\uff1a\u5728\u653e\u7f6e\u7a0b\u5f0f\u78bc\u7684\u76ee\u9304\u4e0b\uff0c\u9032\u884c\u521d\u59cb\u5316\uff0c\u4e26\u8a2d\u5b9a\u4f7f\u7528\u8005\u7684\u8cc7\u8a0a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># git init\n\n# git config --global user.name \"user\"\n# git config --global user.email \"user@xxx.com\u201d\n# git config -\u2013global core.editor vi \n\n\/\/ \u5f9e GitLab \u4e0b\u8f09\u5132\u5b58\u5eab (Remote Repository)\n# git clone &lt;repo URL&gt;\n\n\/\/ \u5728\u5de5\u4f5c\u5340 (Workspace) \u5167\u6307\u5b9a\u7279\u5b9a\u6a94\u6848\u5efa\u7acb\u7d22\u5f15\n# git add readme.txt\n\n\/\/ \u5de5\u4f5c\u76ee\u9304 (Working Directory) \u5167\u6240\u6709\u6a94\u6848\u5efa\u7acb\u7d22\u5f15\n# git add .\n\n\/\/ \u5c07\u5efa\u7acb\u7d22\u5f15\u7684\u6a94\u6848\u63d0\u4ea4\u81f3\u672c\u5730\u8cc7\u6599\u5eab (Local Repository)\n# git commit -m \"todo ....\"\n\n\/\/ \u5982\u679c GitLab \u76ee\u9304\u5167\u6c92\u6709\u5176\u4ed6\u5206\u652f\uff0c\u53ef\u4ee5\u76f4\u63a5\u7528 git push\n# git push\n\n\/\/ \u4e0a\u50b3\u6240\u6709\u5206\u652f\u81f3  GitLab \u76ee\u9304\n# git push --all origin<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Git \u6307\u4ee4\u64cd\u4f5c\u8aaa\u660e<\/h2>\n\n\n\n<p>\u5168\u5c40\u914d\u7f6e<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>\u547d\u4ee4<\/th><th>\u8aaa\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>git config -l<\/code><\/td><td>\u67e5\u770b\u5168\u5c40\u914d\u7f6e<\/td><\/tr><tr><td><code>git config --global user.name [name]<\/code><\/td><td>\u8a2d\u5b9a\u7528\u6237\u540d<\/td><\/tr><tr><td><code>git config --global user.email [email]<\/code><\/td><td>\u8a2d\u5b9aE-Mail<\/td><\/tr><tr><td><code>git config --global core.editor vi  <\/code><\/td><td>\u8a2d\u5b9a\u6587\u5b57\u7de8\u8f2f\u5668\u70ba vi<\/td><\/tr><tr><td><code>git config --global alias.st status<\/code><\/td><td>status \u7e2e\u5beb\u70ba st<\/td><\/tr><tr><td><code>git config --global alias.co checkout<\/code><\/td><td>checkout \u7e2e\u5beb\u70ba co<\/td><\/tr><tr><td><code>git config --global alias.br branch<\/code><\/td><td>branch \u7e2e\u5beb\u70ba br<\/td><\/tr><tr><td><code>git config --global alias.ci commit<\/code><\/td><td>commit \u7e2e\u5beb\u70ba ci<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u5efa\u7acb\u5132\u5b58\u5eab<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>\u547d\u4ee4<\/th><th>\u8aaa\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>git init<\/code><\/td><td>\u521d\u59cb\u5316\u672c\u5730\u5132\u5b58\u5eab<\/td><\/tr><tr><td><code>git clone &lt;url&gt;<\/code><\/td><td>\u4e0b\u8f09\u96f2\u7aef\u5132\u5b58\u5eab<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u4fee\u6539\u548c\u63d0\u4ea4<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>\u547d\u4ee4<\/th><th>\u8aaa\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>git status<\/code><\/td><td>\u67e5\u770b\u6240\u6709\u6587\u4ef6\u72c0\u614b<\/td><\/tr><tr><td><code>git status [FILE]<\/code><\/td><td>\u67e5\u770b\u6307\u5b9a\u6587\u4ef6\u72c0\u614b<\/td><\/tr><tr><td><code>git add .<\/code><\/td><td>\u63d0\u4ea4\u7576\u524d\u76ee\u9304\u6240\u6709\u6587\u4ef6\u5230\u66ab\u5b58\u5340<\/td><\/tr><tr><td><code>git add [FILE]<\/code><\/td><td>\u63d0\u4ea4\u6307\u5b9a\u6587\u4ef6\u5230\u66ab\u5b58\u5340<\/td><\/tr><tr><td><code>git commit -m [message]<\/code><\/td><td>\u63d0\u4ea4\u66ab\u5b58\u5340\u5230\u672c\u5730\u5132\u5b58\u5eab\uff0cmessage\u4ee3\u8868\u8aaa\u660e\u4fe1\u606f<\/td><\/tr><tr><td><code>git commit --amend<\/code><\/td><td>\u63d0\u4ea4\u66ab\u5b58\u5340\u5230\u672c\u5730\u5132\u5b58\u5eab\uff0c\u8986\u84cb\u4e0a\u4e00\u6b21\u63d0\u4ea4<\/td><\/tr><tr><td><code>git diff<\/code><\/td><td>\u67e5\u770b\u8b8a\u66f4\u5185\u5bb9\uff0c\u5c0d\u6bd4\u5de5\u4f5c\u76ee\u9304\u8207\u66ab\u5b58\u5340<br><\/td><\/tr><tr><td><code>git diff --cached<\/code><\/td><td>\u67e5\u770b\u8b8a\u5185\u5bb9\uff0c\u5c0d\u6bd4\u66ab\u5b58\u5340\u8207\u672c\u5730\u5132\u5b58\u5eab<\/td><\/tr><tr><td><code>git diff master origin\/master<\/code><\/td><td>\u67e5\u770b\u8b8a\u66f4\u5185\u5bb9\uff0c\u5c0d\u6bd4\u672c\u5730\u4ee3\u7801\u5e93\u8207\u672c\u5730\u4f3a\u670d\u5668\u5132\u5b58\u5eab\uff0corigin\u4ee3\u8868\u4f3a\u670d \u5668\u7684\u610f\u601d<\/td><\/tr><tr><td><code>git mv [old] [new]<\/code><\/td><td>\u6587\u4ef6\u6539\u540d<\/td><\/tr><tr><td><code>git rm [FILE]<\/code><\/td><td>\u522a\u9664\u6587\u4ef6<\/td><\/tr><tr><td><code>git rm --cached [FILE]<\/code><\/td><td>\u505c\u6b62\u8ddf\u8e2a\u6587\u4ef6\u4f46\u4e0d\u522a\u9664<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>git diff HEAD^ HEAD \/\/ \u6bd4\u8f03\u6700\u65b0\u7248\u8207\u6700\u65b0\u7248\u524d\u4e00\u6b21\u7248\u672c\u7684\u5dee\u7570\r\ngit diff ---stat \/\/ \u6aa2\u8996\u66f4\u65b0\u7684\u7c21\u7565\u7d71\u8a08\u8cc7\u8a0a\u3002\r\ngit diff --name-only \/\/ \u5728\u66f4\u65b0\u7684\u8a0a\u606f\u5f8c\u65b9\u986f\u793a\u66f4\u52d5\u7684\u6a94\u6848\u5217\u8868\u3002\r\ngit diff --name-status \/\/ \u986f\u793a\u65b0\u589e\u3001\u66f4\u52d5\u3001\u522a\u9664\u7684\u6a94\u6848\u5217\u8868\u3002\r\ngit diff --diff-filter= &#91;(A|C|D|M|R|T)\u2026\u200b&#91;*]]] \/\/ \u914d\u5408\u6a94\u6848\u72c0\u614b\u4f86\u7be9\u9078\u986f\u793a\u6a94\u6848\u5217\u8868\u3002\r\nA = Added\r\nC = Copied\r\nM = Modified\r\nR = Renamed\r\nT = Changed\r\nD =Delete<\/code><\/pre>\n\n\n\n<p>\u67e5\u770b\u63d0\u4ea4log<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>\u547d\u4ee4<\/th><th>\u8aaa\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>git log<\/code><\/td><td>\u67e5\u770b\u5132\u5b58\u5eab\u65e5\u5fd7<\/td><\/tr><tr><td><code>git log -p<\/code><\/td><td>\u67e5\u770b\u5132\u5b58\u5eab\u65e5\u5fd7\uff0c\u540c\u65f6\u986f\u793a\u5177\u4f53\u4fee\u6539<\/td><\/tr><tr><td><code>git log -2<\/code><\/td><td>\u67e5\u770b\u5132\u5b58\u5eab\u6700\u8fd1\u4e24\u6b21\u63d0\u4ea4\u7684log<\/td><\/tr><tr><td><code>git log [FILE]<\/code><\/td><td>\u67e5\u770b\u6307\u5b9a\u6587\u4ef6\u7684\u5132\u5b58\u5eablog<\/td><\/tr><tr><td><code>git log --graph --pretty=oneline --abbrev-commit -20<\/code><\/td><td>\u67e5\u770b\u5132\u5b58\u5eablog\uff0c\u7528\u5716\u5f62\u8aaa\u660e<\/td><\/tr><tr><td><code>git reflog<\/code><\/td><td>\u67e5\u770b\u64cd\u4f5c\u8a18\u9304<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u7248\u672c\u56de\u64a4<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>\u547d\u4ee4<\/th><th>\u8aaa\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>git reset HEAD<\/code><\/td><td>\u5c06\u6587\u4ef6\u5f9e\u66ab\u5b58\u5340\u4e2d\u56de\u9000\u5230\u5de5\u4f5c\u5340\uff0cgit add\u7684\u53cd\u64cd\u4f5c<\/td><\/tr><tr><td><code>git reset \u7248\u672c\u53f7\uff08\u524d\u4e03\u4f4d\uff09<\/code><\/td><td>\u9000\u56de\u5230\u6307\u5b9a\u7248\u672c<\/td><\/tr><tr><td><code>git reset --soft HEAD<\/code><\/td><td>\u53ea\u6539\u8b8a\u63d0\u4ea4\u9ede\uff0c\u5de5\u4f5c\u76ee\u9304\u8207\u66ab\u5b58\u5340\u4e2d\u5185\u5bb9\u90fd\u4e0d\u6539\u8b8a<\/td><\/tr><tr><td><code>git reset --hard HEAD<\/code><\/td><td>\u9000\u56de\u5230\u7576\u524d\u7248\u672c\uff0c\u64a4\u92b7\u5de5\u4f5c\u76ee\u9304\u8207\u66ab\u5b58\u5340\u4e2d\u7684\u6240\u6709\u5185\u5bb9<\/td><\/tr><tr><td><code>git reset --hard HEAD^<\/code><\/td><td>\u9000\u56de\u5230\u4e0a\u4e00\u4e2a\u7248\u672c<\/td><\/tr><tr><td><code>git reset --hard HEAD^^<\/code><\/td><td>\u9000\u56de\u5230\u4e0a\u4e0a\u4e00\u4e2a\u7248\u672c<\/td><\/tr><tr><td><code>git reset --hard HEAD~2<\/code><\/td><td>\u9000\u56de\u5230\u4e0a\u4e0a\u4e00\u4e2a\u7248\u672c<\/td><\/tr><tr><td><code>git chechout [FILE]<\/code><\/td><td>\u64a4\u92b7\u67d0\u4e00\u4e2a\u6587\u4ef6\u7576\u524d\u7684\u4fee\u6539<\/td><\/tr><tr><td><code>git revert [CommitID]<\/code><\/td><td>\u64a4\u92b7\u6307\u5b9a\u7684commit\uff0c\u6703\u65b0\u589e\u4e00\u4e2acommit\uff0c\u5c07\u7248\u672c\u6539\u56de\u4fee\u6539\u524d<\/td><\/tr><tr><td><code>git clean -xfd<\/code><\/td><td>\u6e05\u9664\u6240\u6709\u975eGIT\u8ddf\u8e2a\u6587\u4ef6<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u5206\u652fbranch\u64cd\u4f5c<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>\u547d\u4ee4<\/th><th>\u8aaa\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>git branch<\/code><\/td><td>\u67e5\u770b\u672c\u5730\u5206\u652f<\/td><\/tr><tr><td><code>git branch -r<\/code><\/td><td>\u67e5\u770b\u4f3a\u670d\u5668\u5206\u652f<\/td><\/tr><tr><td><code>git branch -a<\/code><\/td><td>\u67e5\u770b\u6240\u6709\u5206\u652f<\/td><\/tr><tr><td><code>git branch [branch-name]<\/code><\/td><td>\u65b0\u5efa\u672c\u5730\u5206\u652f\uff0c\u6ce8\u610f\u4e0d\u4f1a\u81ea\u52d5\u5207\u6362\uff0c\u4f9d\u7136\u505c\u7559\u5728\u7576\u524d\u5206\u652f<\/td><\/tr><tr><td><code>git branch -d [branch-name]<\/code><\/td><td>\u522a\u9664\u5206\u652f\uff0c\u6ce8\u610f\u53ea\u80fd\u522a\u9664\u5df2\u7ecf\u5408\u4f75\u904e\u7684\u5206\u652f<\/td><\/tr><tr><td><code>git checkout [branch\/tag]<\/code><\/td><td>\u5207\u6362\u5230\u6307\u5b9a\u5206\u652f\uff0c\u5e76\u66f4\u65b0\u5de5\u4f5c\u5340<\/td><\/tr><tr><td><code>git checkout -b [branch-name]<\/code><\/td><td>\u65b0\u5efa\u672c\u5730\u5206\u652f\uff0c\u4f75\u5207\u63db\u5230\u5206\u652f<\/td><\/tr><tr><td><code>git tag<\/code><\/td><td>\u67e5\u770b\u6240\u6709\u672c\u5730\u6a19\u7c3d<\/td><\/tr><tr><td><code>git tag [tagname]<\/code><\/td><td>\u5efa\u7acb\u6a19\u7c3d\uff0c\u57fa\u4e8e\u6700\u65b0\u7248\u672c\u63d0\u4ea4<\/td><\/tr><tr><td><code>git tag -a [tagname] -m [message]<\/code><\/td><td>\u5efa\u7acb\u6a19\u7c3d\uff0c\u57fa\u4e8e\u6700\u65b0\u7248\u672c\u63d0\u4ea4\uff0c\u9644\u5e26\u4fe1\u606f<\/td><\/tr><tr><td><code>git tag -a [tagname] -m [message] [CommitID]<\/code><\/td><td>\u5efa\u7acb\u6a19\u7c3d\uff0c\u57fa\u4e8e\u6307\u5b9a\u7684Commit\uff0c\u9644\u5e26\u4fe1\u606f<\/td><\/tr><tr><td><code>git tag -d [tagname]<\/code><\/td><td>\u522a\u9664\u6a19\u7c3d<\/td><\/tr><tr><td><code>git show [tagname]<\/code><\/td><td>\u67e5\u770b\u6307\u5b9a\u6a19\u7c3d\u4fe1\u606f<\/td><\/tr><tr><td><code>git push origin [tagname]:refs\/tags\/[tagname]<\/code><\/td><td>\u66f4\u65b0\u6307\u5b9a\u5206\u652f<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u5408\u5e76\u4e0e\u884d\u5408<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>\u547d\u4ee4<\/th><th>\u8aaa\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>git merge [branch]<\/code><\/td><td>\u5408\u4f75\u6307\u5b9a\u5206\u652f\u5230\u7576\u524d\u5206\u652f<\/td><\/tr><tr><td><code>git rebase [branch]<\/code><\/td><td>\u5408\u4f75\u6307\u5b9a\u5206\u652f\u5230\u7576\u524d\u5206\u652f\uff0c\u5c07\u7576\u524d\u5206\u652f\u7684\u4fee\u6539\u9023\u63a5\u5728\u6307\u5b9a\u5206\u652f\u4e4b\u540e<\/td><\/tr><tr><td><code>git fetch [branch]<\/code><\/td><td>\u5c07\u4f3a\u670d\u5668\u5132\u5b58\u5eab\u7684\u4ee3\u78bc\u66f4\u65b0\u5230\u672c\u5730\u7684\u5132\u5b58\u5eab<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u8fdc\u7a0b\u64cd\u4f5c<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>\u547d\u4ee4<\/th><th>\u8aaa\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>git remote -v<\/code><\/td><td>\u67e5\u770b\u4f3a\u670d\u5668\u7248\u672c\u5eab\u4fe1\u606f<\/td><\/tr><tr><td><code>git remote show [remote]<\/code><\/td><td>\u67e5\u770b\u6307\u5b9a\u4f3a\u670d\u5668\u7248\u672c\u5eab\u4fe1\u606f<\/td><\/tr><tr><td><code>git remote add [remote] [url]<\/code><\/td><td>\u6dfb\u52a0\u4f3a\u670d\u5668\u7248\u672c\u5eab <\/td><\/tr><tr><td><code>git fetch [remote]<\/code><\/td><td>\u5f9e\u4f3a\u670d\u5668\u5132\u5b58\u5eab \u83b7\u53d6\u4ee3\u7801\u5230\u672c\u5730\u5132\u5b58\u5eab <\/td><\/tr><tr><td><code>git pull [remote] [branch]<\/code><\/td><td>\u4e0b\u8f09\u4ee3\u78bc\u53ca\u5feb\u901f\u5408\u4f75<\/td><\/tr><tr><td><code>git push [remote] [branch]<\/code><\/td><td>\u4e0a\u50b3\u4ee3\u78bc\u53ca\u5feb\u901f\u5408\u4f75<\/td><\/tr><tr><td><code>git push [remote]:[branch\/tag-name]<\/code><\/td><td>\u522a\u9664 \u4f3a\u670d\u5668\u5206\u652f\u6216\u6a19\u7c3d<\/td><\/tr><tr><td><code>git push --tags<\/code><\/td><td>\u4e0a\u50b3\u6240\u6709\u6a19\u7c3d <\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u53c3\u8003\u8cc7\u6599<\/p>\n\n\n\n<p><a href=\"https:\/\/b31jsc.github.io\/2018\/06\/13\/Git%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4\/\">https:\/\/b31jsc.github.io\/<\/a><a rel=\"noreferrer noopener\" href=\"https:\/\/b31jsc.github.io\/2018\/06\/13\/Git%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4\/\" target=\"_blank\">2018\/06\/13\/Git%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4\/<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/www.tpisoftware.com\/tpu\/articleDetails\/1450\">https:\/\/www.tpisoftware.com\/tpu\/articleDetails\/1450<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5feb\u901f\u5f15\u5c0e\uff1a\u5728\u653e\u7f6e\u7a0b\u5f0f\u78bc\u7684\u76ee\u9304\u4e0b\uff0c\u9032\u884c\u521d\u59cb\u5316\uff0c\u4e26\u8a2d\u5b9a\u4f7f\u7528\u8005\u7684\u8cc7\u8a0a Git \u6307\u4ee4\u64cd\u4f5c\u8aaa\u660e \u5168\u5c40\u914d\u7f6e \u547d\u4ee4 \u8aaa\u660e g &#8230; <a title=\"Git \u7684\u4f7f\u7528 for Linux\" class=\"read-more\" href=\"https:\/\/www.yaj.com.tw\/wordpress\/?p=220\" aria-label=\"\u95b1\u8b80\u3008Git \u7684\u4f7f\u7528 for Linux\u3009\u5168\u6587\">\u95b1\u8b80\u5168\u6587<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[18,17],"class_list":["post-220","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-gitlab","tag-linux"],"_links":{"self":[{"href":"https:\/\/www.yaj.com.tw\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/220","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yaj.com.tw\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yaj.com.tw\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yaj.com.tw\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yaj.com.tw\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=220"}],"version-history":[{"count":10,"href":"https:\/\/www.yaj.com.tw\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/220\/revisions"}],"predecessor-version":[{"id":471,"href":"https:\/\/www.yaj.com.tw\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/220\/revisions\/471"}],"wp:attachment":[{"href":"https:\/\/www.yaj.com.tw\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yaj.com.tw\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yaj.com.tw\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}