一、基本操作
账号配置
git config --global user.name ‘tom’
git config --global user.email "xinfusong@163.com"
git init
git init //使用当前目录作为Git仓库,我们只需使它初始化
git init newrepo //使用我们指定目录作为Git仓库
git remote add origin https://git.lug.ustc.edu.cn/songxinfu/gittudy.git
touch test.php
git add .
git push origin master
git remote add origin https://gitee.com/xfsong/newrepo.git
https://gitee.com/xfsong/newrepo.git
git clone
git clone //从现有 Git 仓库中拷贝项目到当前目录
git clone //从现有 Git 仓库中拷贝项目到指定目录
git pull
git pull <远程主机名> <远程分支名>:<本地分支名>
//取回远程主机某个分支的更新,再与本地的指定分支合并
git add
git add 将该文件添加到缓存
git add . 将所有文件添加到缓存
git commit
将缓存区内容添加到仓库中
git commit -m “说明”
git status
查看在你上次提交之后是否有修改和分支信息
二、分支管理
git branch
git branch (branchname) 创建分支
git branch 查看分支信息
git branch -d (branchname) //删除分支
git checkout
git checkout (branchname) 切换分支
git checkout – file //会用暂存区全部或指定的文件替换工作区的文件
git checkout -b (branchname) 创建并切换分支
git merge branch1 . 合并分支
git log //git log 命令列出历史提交记录
git log --oneline 查看历史记录的简洁的版本
Git 远程仓库(Github)
git remote add [shortname] [url] //添加远程库
git remote //查看当前配置有哪些远程仓库
git remote -v
git fetch //相当于是从远程获取最新版本到本地,不会自动合并
git merge origin/master
git push [alias] [branch] //推送新分支与数据到某个远端仓库
git remote rm [别名] //删除远程仓库
git remote rm origin2
git reset HEAD //取消已缓存的内容
git reset -–hard commitid