分支操作
创建分支
$ git branch daily/1.0.0
$ git push origin daily/1.0.0
删除分支
注意: 不能在当前分支删除此分支
$ git branch -d daily/1.0.0
$ git push origin :daily/1.0.0
查看分支
$ git branch -a
切换分支
$ git checkout -b dev origin/dev #远程仓库有dev分支, 但本地仓库没有时, 需要在本地创建新的dev分支
$ git checkout dev #本地有dev分支, 直接切换
查看目前状态(是否有本地更改)
$ git status
更新
$ git pull
git提交
$ git add --all 或 git add .
$ git commit -m 'first commit'
$ git push origin master
下载某分支的内容,且本地独立创建
master 为分支名称, myblog 为创建的目录
$ git clone -b master git@github.com:HooChiu/hoochiu.github.io.git myblog
删除文件(远程仓库)
$ git rm -r --cached 文件名称
$ git commit -m "注释"
$ git push
回滚
$ git reset --hard 3d51c955ddfc7a78da531b5c42b34ca2b60ea47b(某次commit编码)
$ git push -f origin 分支名
上线(merge到master分支)
$ git checkout master
$ git pull
$ git merge 分支名 #将分支合并到master上
$ git push origin master
删除tag
$ git tag -a v1.0.0 -m '标记备注' #针对某一时间点做标记
$ git push origin v1.0.0 #v1.0.0 是本次提交过程中的版本号
创建tag(merge到master后需要打tag标记下上线版本)
$ git tag -d v1.0.0 #删除本地tag
$ git push origin :v1.0.0 #删除远程v1.0.0 tag 方案一
$ git push origin --delete tag v1.0.0 #删除远程v1.0.0 tag 方案二
$ git push origin :refs/tags/v1.0.0 #删除远程v1.0.0 tag 方案三
提交日志log
$ git log #查看所有提交记录
$ git log --author 'HooChiu' #查看某用户的提交记录
问题整理
问题一: git add . 时报错
解决方案:
rm -f ./.git/index.lock
问题二: Please enter a commit message to explain why this merge is necessary,especially if it merges an updated upstream into a topic branch.Lines starting with '#' will be ignored, and an empty message aborts the commit.
问题复现场景:
git pull 或者合并分支时
解决方案:
按键盘字母 i 进入insert模式修改最上面那行黄色合并信息,可以不修改按键盘左上角"Esc"输入":wq",注意是冒号+wq,按回车键即可或者":wq!"
问题三:
➜ ~ brew -v
Homebrew >1.2.0 (no git repository)
Homebrew/homebrew-core (no git repository)
Warning: git 2.14.1 is already installed
git -v
xcode-select: note: no developer tools were found at '/Applications/Xcode.app', requesting install. Choose an option in the dialog to download the command line developer tools.
解决方案:
export PATH="/usr/local/bin:$PATH"
➜ ~ git --version
git version 2.14.1
转载于:https://www.cnblogs.com/hchiu/p/7928727.html
相关资源:数据结构—成绩单生成器