Git安装
查看账户
git config user.name
git config user.email
git config --global user.name 'name'
git config --global user.eamil 'email'
# --global 登陆用户所有仓库有效
# --local 对本仓库有效
# --system 对系统所有登录用户有效
创建repository
命令行:
本地创建库
- 新建库文件夹,右键菜单选择 git bash here
- 初始化库
git init
云端库克隆到本地文件夹
选择本地文件夹右键 Git Bash here
# url = github/gitee code
git clone url
成功clone到本地
云端库关联
- 查看关联列表
git remote -v
- 删除
git remote rm origin
- 添加
git remote add origin ==github项目.git(http/SSH)==
- 上传
git push --set-upstream origin master # --set 设置分支名
git push origin branch_name
图形化界面:Github DeskTop
commit & 恢复
修改源码后
- 查看修改状态
git status
标记新创建文件 test.txt为红色
2. 指定即将提交的文件
git add ./filename # (.表示当前文件夹,可以选择文件名)
3. 提交
git commit -a -m "一定要添加注释"
- 查询commit记录
git log
- 回退记录
git reset --hard commid_id
push & pull
- 本地库同步到云端
git push origin
首次push,可以根据提示来
git push --set-upstream origin master
- 云端拉取内容
git pull
分支branch
分支上的操作只影响当前分支,不影响其他内容
开发时尽量使用分支,常用commit避免出错
# 查看分支
git branch
# 切换分支
git checkout branch_id
# 新建并切换分支
git checkout -b new_branch
# 合并分支
git merge branch_id # 将分支branch_id合并到 当前 分支
# 删除分支
git branch -D