git 常用命令
git remote show
git remote show origin
git remote remove origin
git remote add origin http://code.slac.com.cn/huangzh/ESIF
git config --global alias.lg "log --graph --pretty=format:'%C(auto)%h -%d %s %C(cyan)%an %C(red)A[%ad] %C(magenta)C[%]' --date=format:%m-%d/%H:%M --all"
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
git lg
git diff
git diff --stat
git add Task_ImageSource_File/Entry_ImageSource_File.cpp
git diff --cached
git commit
git push origin master
git fetch origin master
git rebase origin/master
git status
git stash
git stash pop
git push origin master
git push origin master -f 强制合并,origin是我的远程库,master是本地库
git rebase -i esif/master //-i是交叉的意思,交叉rebase到esif/master库
rm -fr ".../rebase-apply" 删除没有完成的rebase
git fetch esif master //取下远程库
git remote show esif //查看远程主库esif
git remote show origin //查看我的远程库origin
git show 3f59adc //查看id号为3f59adc的提交
git checkout master //checkout我的远程库到本地库master
第一部分:Git的基本操作
初始化操作
$ git config -global user.name <name>
$ git config -global user.password <password>
$ git config -global user.email <email>
$ git config -global core.editor <editor>
$ git config -global merge.tool <tool>
$ git config -list
创建新版本库
$ git clone <url>
$ git init
修改和提交
$ git config --global core.excludesfile d:/.gitignore 设置全局的忽略文件
$ git add .
$ git add <file>
$ git mv <old> <new>
$ git rm <file>
$ git rm -cached <file>
$ git rm -f -r --cached .
$ git rm -rf --cached <file>
$ git commit -m <file>
$ git commit -m “commit message”
$ git commit -amend
$ git commit -C HEAD -a -amend
查看提交历史
$ git log
$ git log -p <file>
$ git blame <file>
$ gitk
$ gitk <branch>
$ gitk --all
$ git branch -v
$ git status
$ git diff
撤消操作
$ git reset --hard HEAD
$ git checkout HEAD <file1> <file2>
$ git checkout HEAD.
$ git revert <commit>
隐藏操作
$ git stash
git stash save "save message" : 执行存储时,添加备注,方便查找,只有git stash 也要可以的,但查找时不方便识别。
git stash list :查看stash了哪些存储
git stash show :显示做了哪些改动,默认show第一个存储,如果要显示其他存贮,后面加stash@{$num},比如第二个 git stash show stash@{1}
git stash show -p : 显示第一个存储的改动,如果想显示其他存存储,命令:git stash show stash@{$num} -p ,比如第二个:git stash show stash@{1} -p
git stash apply :应用某个存储,但不会把存储从存储列表中删除,默认使用第一个存储,即stash@{0},如果要使用其他个,git stash apply stash@{$num} , 比如第二个:git stash apply stash@{1}
git stash pop :命令恢复之前缓存的工作目录,将缓存堆栈中的对应stash删除,并将对应修改应用到当前的工作目录下,默认为第一个stash,即stash@{0},如果要应用并删除其他stash,命令:git stash pop stash@{$num} ,比如应用并删除第二个:git stash pop stash@{1}
git stash drop stash@{$num} :丢弃stash@{$num}存储,从列表中删除这个存储
git stash clear :删除所有缓存的stas
分支与标签
$ git branch
$ git checkout <branch/tagname>
$ git branch <new-branch>
$ git branch -d <branch>
$ git tag
$ git tag <tagname>
$ git tag -d <tagname>
$ git fetch origin dev:dev
合并与衍合
$ git merge <branch>
$ git rebase <branch>
远程操作
$ git config --system --unset credential.helper
$ git config --global credential.helper store
$ git remote -v
$ git remote show <remote>
$ git remote add <remote> <url>
$ git fetch <remote>
$ git pull <remote> <branch>
$ git push <remote> <branch>
$ git push <remote> : <branch>/<tagname>
$ git push -tags
$ git pull <远程库名> <远程分支名>:<本地分支名>
比如,取回远程库中的online分支,与本地的online分支进行merge,要写成:git pull origin online:online
如果是要与本地当前分支merge,则冒号后面的<本地分支名>可以不写 git pull origin online
git推送本地分支到远程分支
$ git checkout -b feature-branch origin/feature-branch //检出远程的feature-branch分支到本地
$ git checkout -b newbranch //创建并切换到分支newbranch
$ git push origin newbranch:newbranch //推送本地的newbranch(冒号前面的)分支到远程origin的newbranch(冒号后面的)分支(没有会自动创建)
git 出现 fatal: refusing to merge unrelated histories 错误
git pull or push 失败 ,提示:fatal: refusing to merge unrelated histories
//其实这个问题是因为 两个 根本不相干的 git 库, 一个是本地库, 一个是远端库, 然后本地要去推送到远端, 远端觉得这个本地库跟自己不相干, 所以告知无法合并
git pull/push origin master --allow-unrelated-histories
后面加上 --allow-unrelated-histories , 把两段不相干的 分支进行强行合并
//
2. 查看所有分支
git branch --all(或者--all这里直接-a简写)
3. 创建本地新的dev分支
git branch dev
git branch
4. 发布dev分支
发布dev分支指的是同步dev分支的代码到远程服务器
git push origin dev:dev
5. 在dev分支开发代码
git checkout dev
git checkout master
git merge dev
git push
git checkout dev
git push
git push
6. 删除分支
git push origin :dev
git checkout master
git branch -d dev