git安装 1 2 3 4 5 6 7 8 1.windows系统 https://git-scm.com/download/win 2.linux系统 yum install git -y 3.macos系统 https://git-scm.com/download/mac
本地仓库 基本使用 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 mkdir app cd appgit init ls -a echo 'app01 20%' > index.htmlgit status git add index.html git add . git config --global user.email "2564334707@qq.com" git config --global user.name "klcc" git config --global --list git config --global color.ui true git commit -m "app is 20% --v1" git log echo 'app is complete' >> index.htmlgit add . git commit -m "app complete --v2" git log git reset --hard ID git reflog
基础命令总结 1 2 3 4 5 6 7 8 9 10 11 12 13 git init git add git commit git log git reflog git reset --hard git status git checkout git reset HEAD .git文件夹做了记录,不能删除,如果删除,版本的记录也就没了 空文件夹不会被版本管理
分支使用 分支可以给使用者提供多个环境的可以,意味着你可以把你的工作从开发主线上分离开来,以免影响开发主线
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 git branch git branch dev git checkout dev echo 'shopping system is 20%' > shopping.pygit add . git commit -m 'shopping system 20% --v3' echo 'shopping system is 50%' >> shopping.pygit add . git commit -m 'shopping system 50% --v4' git checkout master git branch git branch bug git checkout bug git branch echo 'bug repair' >> index.htmlgit add . git commit -m 'app bug repair --v5' git checkout master git branch git merge bug -m 'app bug repair master merge bug --v6' git checkout dev git branch echo 'shopping system is 100%' >> shopping.pygit add . git commit -m 'shopping system 100% --v7' git merge master -m 'dev merge master test shopping --v8' git checkout master git branch git merge dev -m 'master merge dev shop system --v9'
分支命令总结 1 2 3 4 5 6 7 git branch git branch name git checkout -b name git checkout name git branch -d name git branch -a git merge dev
远程仓库 基本使用
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 git remote add origin git@gitee.com:liuzhijin1/gittest.git git remote -v git remote rm origin git config --local --list git push origin master git checkout dev git push origin dev git clone git@gitee.com:liuzhijin1/gittest.git ... git pull origin master
总结 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 git clone 第一次必须要克隆项目 git pull origin master git push origin master 等价于 git fetch origin git merge origin/dev git remote add origin 地址 git remote -v git remote git remote remove origin git push origin dev git log --graph --pretty=format:"%h %s"
其他补充 tag
标签git标签就是对commit的一次快照,便于后续将特定时期 的代码快速取出,在代码发布时可以使用标签发布
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 git tag -a "v1.1" -m "描述信息" git tag -a v1.2 CommitID -m "Messages" git tag git log -l git tag -a v2.0 -m "shopping up" git push origin --tags git reflog git tag -a v1.0 f4ad9ef -m "app complete" git push orgin --tag v1.0 git show v1.0
免密登录 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 git remote add origin https://用户名:密码@gitee.com/xxx/treenb.git git push origin maste ssh-keygen git remote add origin git@github.com:/dbhot.git git push origin master
ignore
文件忽略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 让 Git 不再管理当前目录下的某些文件 .gitignore 通常情况下有如下文件可能需要忽略 1.程序运行时产生的垃圾文件 2.程序运行时产生的缓存文件 3.程序本地开发使用的图片文件 4.程序连接数据一类的配置文件 例如以下文件类型: .idea/ *.h !a.h files/ *.py[c|a|d] cd workdircat .gitignore *.pyc git add . git commit -m "ignore" git push origin master touch a.txt touch 1.pyc touch 2.pyc git status