CREATE
-新建远程仓库,本地创建项目与连接:
- 仓库创建一个新项目,项目名与本地项目名同名 - 复制仓库新项目的代码地址(HTTPS/ssh)
- 在项目一级目录下:
- git init # 当前项目目录生产本地Git管理和.git 目录
- git add . # 添加所有文件
- git commit -m “备注”
- git remote add origin http://yourproject.address.git origin
- git push -u origin master # 提交
-从A系统迁移到B系统
- git push --mirror http://yourproject.address.git
BRANCH
- 创建分支
git checkout -b feature_x- 切回其他分支(master)
git checkout master- 存在分支,提交需指明分支名/追踪
git push origin feature_x- 删除分支–没有pull的情况下feature_x 只对自己可见
git branch -d feature_x- 合并其他分支到当前分支
git merge feature_x- 分支对比
git diff feature_1 feature_2
TAG & LOG
git log
git tag x.x.x abcdef(提交ID的前10位(建议)字符)
ERRORS
remote origin already existes
解决:删除远程库
git remote add origin/或删除.git/config中remote两句/直接删除.git文件I don’t handle protocol ‘–https’
解决:命令重新输入,可能有unicode码之类的。failed to push some refs to ‘https://github.com/QuasimodoZ/xx.git’
Updates were rejected because the tip of your current branch is behind its remote counterpart. Integrate the remote changes (e.g.‘git pull …’) before pushing again.See the ‘Note about fast-forwards’ in ‘git push --help’ for details.
原因:最新提交和之前的提交有冲突(常出现于多人协作)
解决:git pull 并解决冲突git pull 失败:
原因:远程和本地分支未指定链接,仔细看返回的原因,大部分有提示
解决:git branch --set-upstream-to=remotes/origin/master(远程分支git branch -a查看远程分支名) master(本地分支)
给已有的commit更改名称
git commit --amend 更改上且仅一次未push的commit名称