1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | 查看、添加、提交、删除、找回,重置修改文件 git help < command > # 显示command的help git show # 显示某次提交的内容 git show $id git co -- < file > # 抛弃工作区修改 git co . # 抛弃工作区修改 git add < file > # 将工作文件修改提交到本地暂存区 git add . # 将所有修改过的工作文件提交暂存区 git rm < file > # 从版本库中删除文件 git rm < file > --cached # 从版本库中删除文件,但不删除文件 git reset < file > # 从暂存区恢复到工作文件 git reset -- . # 从暂存区恢复到工作文件 git reset --hard # 恢复最近一次提交过的状态,即放弃上次提交后的所有本次修改 git ci < file > git ci . git ci -a # 将git add, git rm和git ci等操作都合并在一起做 git ci -am "some comments" git ci --amend # 修改最后一git diff <branch1>..<branch2> # 在两个分支之间比较 git diff --staged # 比较暂存区和版本库差异 git diff --cached # 比较暂存区和版本库差异 git diff --stat # 仅仅比较统计信息 次提交记录 git revert <$ id > # 恢复某次提交的状态,恢复动作本身也创建次提交对象 git revert HEAD # 恢复最后一次提交的状态 查看文件 diff git diff < file > # 比较当前文件和暂存区文件差异 git diff git diff <id1><id2> # 比较两次提交之间的差异 查看提交记录 git log git log < file > # 查看该文件每次提交记录 git log -p < file > # 查看每次详细修改内容的diff git log -p -2 # 查看最近两次详细修改内容的diff git log --stat #查看提交统计信息 tig Mac上可以使用tig代替 diff 和log,brew install tig Git 本地分支管理 查看、切换、创建和删除分支 git br -r # 查看远程分支 git br <new_branch> # 创建新的分支 git br - v # 查看各个分支最后提交信息 git br --merged # 查看已经被合并到当前分支的分支 git br --no-merged # 查看尚未被合并到当前分支的分支 git co <branch> # 切换到某个分支 git co -b <new_branch> # 创建新的分支,并且切换过去 git co -b <new_branch> <branch> # 基于branch创建新的new_branch git co $ id # 把某次历史提交记录checkout出来,但无分支信息,切换到其他分支会自动删除 git co $ id -b <new_branch> # 把某次历史提交记录checkout出来,创建成一个分支 git br -d <branch> # 删除某个分支 git br -D <branch> # 强制删除某个分支 (未被合并的分支被删除的时候需要强制) 分支合并和rebase git merge <branch> # 将branch分支合并到当前分支 git merge origin /master --no-ff # 不要Fast-Foward合并,这样可以生成merge提交 git rebase master <branch> # 将master rebase到branch,相当于: git co <branch> && git rebase master && git co master && git merge <branch> Git补丁管理(方便在多台机器上开发同步时用) git diff > .. /sync .patch # 生成补丁 git apply .. /sync .patch # 打补丁 git apply --check .. /sync .patch #测试补丁能否成功 Git暂存管理 git stash # 暂存 git stash list # 列所有stash git stash apply # 恢复暂存的内容 git stash drop # 删除暂存区 Git远程分支管理 git pull # 抓取远程仓库所有分支更新并合并到本地 git pull --no-ff # 抓取远程仓库所有分支更新并合并到本地,不要快进合并 git fetch origin # 抓取远程仓库更新 git merge origin /master # 将远程主分支合并到本地当前分支 git co --track origin /branch # 跟踪某个远程分支创建相应的本地分支 git co -b <local_branch> origin/<remote_branch> # 基于远程分支创建本地分支,功能同上 git push # push所有分支 git push origin master # 将本地主分支推到远程主分支 git push -u origin master # 将本地主分支推到远程(如无远程主分支则创建,用于初始化远程仓库) git push origin <local_branch> # 创建远程分支, origin是远程仓库名 git push origin <local_branch>:<remote_branch> # 创建远程分支 git push origin :<remote_branch> #先删除本地分支(git br -d <branch>),然后再push删除远程分支 Git远程仓库管理 GitHub git remote - v # 查看远程服务器地址和仓库名称 git remote show origin # 查看远程服务器仓库状态 git remote add origin git@ github:robbin /robbin_site .git # 添加远程仓库地址 git remote set -url origin git@ github.com:robbin /robbin_site .git # 设置远程仓库地址(用于修改远程仓库地址) git remote rm <repository> # 删除远程仓库 创建远程仓库 git clone --bare robbin_site robbin_site.git # 用带版本的项目创建纯版本仓库 scp -r my_project.git git@ git.csdn.net:~ # 将纯仓库上传到服务器上 mkdir robbin_site.git && cd robbin_site.git && git --bare init # 在服务器创建纯仓库 git remote add origin git@ github.com:robbin /robbin_site .git # 设置远程仓库地址 git push -u origin master # 客户端首次提交 |
1 2 3 4 5 6 | [root@jdu4e00u53f7 ~] # mkdir Code [root@jdu4e00u53f7 ~] # cd Code/ [root@jdu4e00u53f7 Code] # mkdir CV [root@jdu4e00u53f7 Code] # cd CV [root@jdu4e00u53f7 CV] # ls [root@jdu4e00u53f7 CV] # git init |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | [root@jdu4e00u53f7 CV] # wget http://labfile.oss.aliyuncs.com/courses/624/cv-template.zip --2017-07-25 09:59:13-- http: //labfile .oss.aliyuncs.com /courses/624/cv-template .zip Resolving labfile.oss.aliyuncs.com... 118.178.161.16 Connecting to labfile.oss.aliyuncs.com|118.178.161.16|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 156602 (153K) [application /zip ] Saving to: “cv-template.zip” 100%[====================================================================>] 156,602 --.-K /s in 0.1s 2017-07-25 09:59:13 (1.26 MB /s ) - “cv-template.zip” saved [156602 /156602 ] [root@jdu4e00u53f7 CV] # unzip cv-template.zip Archive: cv-template.zip creating: cv-template/ inflating: cv-template/.DS_Store creating: __MACOSX/ creating: __MACOSX /cv-template/ inflating: __MACOSX /cv-template/ ._.DS_Store inflating: cv-template /index .html creating: cv-template /static/ inflating: cv-template /static/ .DS_Store creating: __MACOSX /cv-template/static/ inflating: __MACOSX /cv-template/static/ ._.DS_Store creating: cv-template /static/css/ inflating: cv-template /static/css/ .DS_Store creating: __MACOSX /cv-template/static/css/ inflating: __MACOSX /cv-template/static/css/ ._.DS_Store inflating: cv-template /static/css/style .css creating: cv-template /static/fonts/ inflating: cv-template /static/fonts/ .DS_Store creating: __MACOSX /cv-template/static/fonts/ inflating: __MACOSX /cv-template/static/fonts/ ._.DS_Store inflating: cv-template /static/fonts/demo .css inflating: cv-template /static/fonts/demo .html inflating: cv-template /static/fonts/iconfont .css inflating: cv-template /static/fonts/iconfont .eot inflating: cv-template /static/fonts/iconfont .svg inflating: cv-template /static/fonts/iconfont .ttf inflating: cv-template /static/fonts/iconfont .woff creating: cv-template /static/image/ inflating: cv-template /static/image/ .DS_Store creating: __MACOSX /cv-template/static/image/ inflating: __MACOSX /cv-template/static/image/ ._.DS_Store inflating: cv-template /static/image/bg .jpg inflating: cv-template /static/image/weixin .png creating: cv-template /static/js/ inflating: cv-template /static/js/ .DS_Store creating: __MACOSX /cv-template/static/js/ inflating: __MACOSX /cv-template/static/js/ ._.DS_Store inflating: cv-template /static/js/modal .js inflating: cv-template /static/js/script .js [root@jdu4e00u53f7 CV] # mv cv-template/* . [root@jdu4e00u53f7 CV] # rm -rf cv-template* cv-template/ cv-template.zip [root@jdu4e00u53f7 CV] # rm -rf cv-template* __MACOSX* [root@jdu4e00u53f7 CV] # firefox index.html Error: GDK_BACKEND does not match available displays [root@jdu4e00u53f7 CV] # ls index.html static [root@jdu4e00u53f7 CV] # yum install Xvfb libXfont xorg-x11-fonts* #下载界面运行 Loaded plugins: fastestmirror Setting up Install Process Loading mirror speeds from cached hostfile epel /metalink | 6.2 kB 00:00 * epel: ftp .cuhk.edu.hk base | 3.7 kB 00:00 extras | 3.4 kB 00:00 updates | 3.4 kB 00:00 Package xorg-x11-server-Xvfb-1.17.4-16.el6.centos.x86_64 already installed and latest version Package libXfont-1.5.1-2.el6.x86_64 already installed and latest version Package xorg-x11-fonts-Type1-7.2-11.el6.noarch already installed and latest version Resolving Dependencies --> Running transaction check ---> Package xorg-x11-fonts-100dpi.noarch 0:7.2-11.el6 will be installed ---> Package xorg-x11-fonts-75dpi.noarch 0:7.2-11.el6 will be installed ---> Package xorg-x11-fonts-ISO8859-1-100dpi.noarch 0:7.2-11.el6 will be installed ---> Package xorg-x11-fonts-ISO8859-1-75dpi.noarch 0:7.2-11.el6 will be installed ---> Package xorg-x11-fonts-ISO8859-14-100dpi.noarch 0:7.2-11.el6 will be installed ---> Package xorg-x11-fonts-ISO8859-14-75dpi.noarch 0:7.2-11.el6 will be installed ---> Package xorg-x11-fonts-ISO8859-15-100dpi.noarch 0:7.2-11.el6 will be installed ---> Package xorg-x11-fonts-ISO8859-15-75dpi.noarch 0:7.2-11.el6 will be installed ---> Package xorg-x11-fonts-ISO8859-2-100dpi.noarch 0:7.2-11.el6 will be installed ---> Package xorg-x11-fonts-ISO8859-2-75dpi.noarch 0:7.2-11.el6 will be installed ---> Package xorg-x11-fonts-ISO8859-9-100dpi.noarch 0:7.2-11.el6 will be installed ---> Package xorg-x11-fonts-ISO8859-9-75dpi.noarch 0:7.2-11.el6 will be installed ---> Package xorg-x11-fonts-cyrillic.noarch 0:7.2-11.el6 will be installed ---> Package xorg-x11-fonts-ethiopic.noarch 0:7.2-11.el6 will be installed ---> Package xorg-x11-fonts-misc.noarch 0:7.2-11.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================== Package Arch Version Repository Size ============================================================================================================== Installing: xorg-x11-fonts-100dpi noarch 7.2-11.el6 base 3.1 M xorg-x11-fonts-75dpi noarch 7.2-11.el6 base 2.8 M xorg-x11-fonts-ISO8859-1-100dpi noarch 7.2-11.el6 base 1.1 M xorg-x11-fonts-ISO8859-1-75dpi noarch 7.2-11.el6 base 933 k xorg-x11-fonts-ISO8859-14-100dpi noarch 7.2-11.el6 base 1.0 M xorg-x11-fonts-ISO8859-14-75dpi noarch 7.2-11.el6 base 906 k xorg-x11-fonts-ISO8859-15-100dpi noarch 7.2-11.el6 base 1.1 M xorg-x11-fonts-ISO8859-15-75dpi noarch 7.2-11.el6 base 932 k xorg-x11-fonts-ISO8859-2-100dpi noarch 7.2-11.el6 base 1.0 M xorg-x11-fonts-ISO8859-2-75dpi noarch 7.2-11.el6 base 901 k xorg-x11-fonts-ISO8859-9-100dpi noarch 7.2-11.el6 base 1.1 M xorg-x11-fonts-ISO8859-9-75dpi noarch 7.2-11.el6 base 930 k xorg-x11-fonts-cyrillic noarch 7.2-11.el6 base 395 k xorg-x11-fonts-ethiopic noarch 7.2-11.el6 base 150 k xorg-x11-fonts-misc noarch 7.2-11.el6 base 5.8 M Transaction Summary ============================================================================================================== Install 15 Package(s) Total download size: 22 M Installed size: 23 M Is this ok [y /N ]: y Downloading Packages: (1 /15 ): xorg-x11-fonts-100dpi-7.2-11.el6.noarch.rpm | 3.1 MB 00:00 (2 /15 ): xorg-x11-fonts-75dpi-7.2-11.el6.noarch.rpm | 2.8 MB 00:00 (3 /15 ): xorg-x11-fonts-ISO8859-1-100dpi-7.2-11.el6.noarch.rpm | 1.1 MB 00:00 (4 /15 ): xorg-x11-fonts-ISO8859-1-75dpi-7.2-11.el6.noarch.rpm | 933 kB 00:00 (5 /15 ): xorg-x11-fonts-ISO8859-14-100dpi-7.2-11.el6.noarch.rpm | 1.0 MB 00:00 (6 /15 ): xorg-x11-fonts-ISO8859-14-75dpi-7.2-11.el6.noarch.rpm | 906 kB 00:00 (7 /15 ): xorg-x11-fonts-ISO8859-15-100dpi-7.2-11.el6.noarch.rpm | 1.1 MB 00:00 (8 /15 ): xorg-x11-fonts-ISO8859-15-75dpi-7.2-11.el6.noarch.rpm | 932 kB 00:00 (9 /15 ): xorg-x11-fonts-ISO8859-2-100dpi-7.2-11.el6.noarch.rpm | 1.0 MB 00:00 (10 /15 ): xorg-x11-fonts-ISO8859-2-75dpi-7.2-11.el6.noarch.rpm | 901 kB 00:00 (11 /15 ): xorg-x11-fonts-ISO8859-9-100dpi-7.2-11.el6.noarch.rpm | 1.1 MB 00:00 (12 /15 ): xorg-x11-fonts-ISO8859-9-75dpi-7.2-11.el6.noarch.rpm | 930 kB 00:00 (13 /15 ): xorg-x11-fonts-cyrillic-7.2-11.el6.noarch.rpm | 395 kB 00:00 (14 /15 ): xorg-x11-fonts-ethiopic-7.2-11.el6.noarch.rpm | 150 kB 00:00 (15 /15 ): xorg-x11-fonts-misc-7.2-11.el6.noarch.rpm | 5.8 MB 00:00 -------------------------------------------------------------------------------------------------------------- Total 11 MB /s | 22 MB 00:01 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : xorg-x11-fonts-ISO8859-9-100dpi-7.2-11.el6.noarch 1 /15 Installing : xorg-x11-fonts-ISO8859-15-100dpi-7.2-11.el6.noarch 2 /15 Installing : xorg-x11-fonts-ethiopic-7.2-11.el6.noarch 3 /15 Installing : xorg-x11-fonts-ISO8859-2-100dpi-7.2-11.el6.noarch 4 /15 Installing : xorg-x11-fonts-ISO8859-15-75dpi-7.2-11.el6.noarch 5 /15 Installing : xorg-x11-fonts-ISO8859-1-100dpi-7.2-11.el6.noarch 6 /15 Installing : xorg-x11-fonts-cyrillic-7.2-11.el6.noarch 7 /15 Installing : xorg-x11-fonts-misc-7.2-11.el6.noarch 8 /15 Installing : xorg-x11-fonts-ISO8859-14-75dpi-7.2-11.el6.noarch 9 /15 Installing : xorg-x11-fonts-ISO8859-2-75dpi-7.2-11.el6.noarch 10 /15 Installing : xorg-x11-fonts-ISO8859-1-75dpi-7.2-11.el6.noarch 11 /15 Installing : xorg-x11-fonts-75dpi-7.2-11.el6.noarch 12 /15 Installing : xorg-x11-fonts-ISO8859-14-100dpi-7.2-11.el6.noarch 13 /15 Installing : xorg-x11-fonts-100dpi-7.2-11.el6.noarch 14 /15 Installing : xorg-x11-fonts-ISO8859-9-75dpi-7.2-11.el6.noarch 15 /15 Verifying : xorg-x11-fonts-ISO8859-9-75dpi-7.2-11.el6.noarch 1 /15 Verifying : xorg-x11-fonts-100dpi-7.2-11.el6.noarch 2 /15 Verifying : xorg-x11-fonts-ISO8859-14-100dpi-7.2-11.el6.noarch 3 /15 Verifying : xorg-x11-fonts-75dpi-7.2-11.el6.noarch 4 /15 Verifying : xorg-x11-fonts-ISO8859-1-75dpi-7.2-11.el6.noarch 5 /15 Verifying : xorg-x11-fonts-ISO8859-2-75dpi-7.2-11.el6.noarch 6 /15 Verifying : xorg-x11-fonts-ISO8859-14-75dpi-7.2-11.el6.noarch 7 /15 Verifying : xorg-x11-fonts-misc-7.2-11.el6.noarch 8 /15 Verifying : xorg-x11-fonts-cyrillic-7.2-11.el6.noarch 9 /15 Verifying : xorg-x11-fonts-ISO8859-1-100dpi-7.2-11.el6.noarch 10 /15 Verifying : xorg-x11-fonts-ISO8859-15-75dpi-7.2-11.el6.noarch 11 /15 Verifying : xorg-x11-fonts-ISO8859-2-100dpi-7.2-11.el6.noarch 12 /15 Verifying : xorg-x11-fonts-ethiopic-7.2-11.el6.noarch 13 /15 Verifying : xorg-x11-fonts-ISO8859-15-100dpi-7.2-11.el6.noarch 14 /15 Verifying : xorg-x11-fonts-ISO8859-9-100dpi-7.2-11.el6.noarch 15 /15 Installed: xorg-x11-fonts-100dpi.noarch 0:7.2-11.el6 xorg-x11-fonts-75dpi.noarch 0:7.2-11.el6 xorg-x11-fonts-ISO8859-1-100dpi.noarch 0:7.2-11.el6 xorg-x11-fonts-ISO8859-1-75dpi.noarch 0:7.2-11.el6 xorg-x11-fonts-ISO8859-14-100dpi.noarch 0:7.2-11.el6 xorg-x11-fonts-ISO8859-14-75dpi.noarch 0:7.2-11.el6 xorg-x11-fonts-ISO8859-15-100dpi.noarch 0:7.2-11.el6 xorg-x11-fonts-ISO8859-15-75dpi.noarch 0:7.2-11.el6 xorg-x11-fonts-ISO8859-2-100dpi.noarch 0:7.2-11.el6 xorg-x11-fonts-ISO8859-2-75dpi.noarch 0:7.2-11.el6 xorg-x11-fonts-ISO8859-9-100dpi.noarch 0:7.2-11.el6 xorg-x11-fonts-ISO8859-9-75dpi.noarch 0:7.2-11.el6 xorg-x11-fonts-cyrillic.noarch 0:7.2-11.el6 xorg-x11-fonts-ethiopic.noarch 0:7.2-11.el6 xorg-x11-fonts-misc.noarch 0:7.2-11.el6 Complete! |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | [root@jdu4e00u53f7]:Code/ (master*) $ git add . [14:19:24] [root@jdu4e00u53f7]:Code/ (master*) $ git commit -m 'commint my cv' [14:19:31] [master (root-commit) c946e97] commint my cv 19 files changed, 1562 insertions(+) create mode 100644 index.html create mode 100644 static/.DS_Store create mode 100644 static /css/ .DS_Store create mode 100644 static /css/style .css create mode 100644 static /fonts/ .DS_Store create mode 100644 static /fonts/demo .css create mode 100644 static /fonts/demo .html create mode 100644 static /fonts/iconfont .css create mode 100644 static /fonts/iconfont .eot create mode 100644 static /fonts/iconfont .svg create mode 100644 static /fonts/iconfont .ttf create mode 100644 static /fonts/iconfont .woff create mode 100644 static /image/ .DS_Store create mode 100644 static /image/bg .jpg create mode 100755 static /image/bg1 .jpg create mode 100644 static /image/weixin .png create mode 100644 static /js/ .DS_Store create mode 100644 static /js/modal .js create mode 100644 static /js/script .js [root@jdu4e00u53f7]:Code/ (master) $ git config --global user.name "haoziyunwei" [14:30:42] [root@jdu4e00u53f7]:Code/ (master) $ git config --global user.email "312779641@qq.com" [14:31:47] git push -f [14:38:13] warning: push.default is unset ; its implicit value is changing in Git 2.0 from 'matching' to 'simple' . To squelch this message and maintain the current behavior after the default changes, use: git config --global push.default matching To squelch this message and adopt the new behavior now, use: git config --global push.default simple When push.default is set to 'matching' , git will push local branches to the remote branches that already exist with the same name. In Git 2.0, Git will default to the more conservative 'simple' behavior, which only pushes the current branch to the corresponding remote branch that 'git pull' uses to update the current branch. See 'git help config' and search for 'push.default' for further information. (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode 'current' instead of 'simple' if you sometimes use older versions of Git) Username for 'https://github.com' : haoziyunwei Password for 'https://haoziyunwei@github.com' : Counting objects: 26, done . Delta compression using up to 4 threads. Compressing objects: 100% (26 /26 ), done . Writing objects: 100% (26 /26 ), 1013.62 KiB | 0 bytes /s , done . Total 26 (delta 6), reused 0 (delta 0) Username for 'https://github.com' : 312779641@qq.com Password for 'https://312779641@qq.com@github.com' : Counting objects: 41, done . Delta compression using up to 4 threads. Compressing objects: 100% (41 /41 ), done . Writing objects: 100% (41 /41 ), 1.09 MiB | 219.00 KiB /s , done . Total 41 (delta 9), reused 0 (delta 0) remote: Resolving deltas: 100% (9 /9 ), done . To https: //github .com /haoziyunwei/cv * [new branch] master -> master Branch master set up to track remote branch master from origin. |