手机登录/注册
X
登录
几个专用名词的译名如下: Workspace:
工作区 Index / Stage:
暂存区 Repository:
仓库区(或本地仓库) Remote:远程仓库
git init
git init [project-name]
git clone [url]
Git的设置文件为.gitconfig,它可以在用户主目录下(全局配置),也可以在项目目录下(项目配置)
git config --list
git config -e [--global]
git config [--global] user.name "[name]"
git config [--global] user.email "[email address]"
git config --global color.ui true # git status等命令自动着色
git config --global color.status auto
git config --global color.diff auto
git config --global color.branch auto
git config --global color.interactive auto
git config --global --unset http.proxy # remove proxy configuration on git
三、增加/删除文件
git add [file1] [file2] ...
git add [dir]
git add .
git add -p
git rm [file1] [file2] ...
git rm --cached [file]
git mv [file-original] [file-renamed]
四、代码提交
git commit -m [message]
git commit [file1] [file2] ... -m [message]
git commit -a
git commit -v
git commit -am 'message'
git commit --amend -m [message]
git commit --amend [file1] [file2] ...
五、分支
git remote update origin --prune
git branch
git branch -r
git branch -a
git branch [branch-name]
git checkout -b [branch]
git branch [branch] [commit]
git branch --track [branch] [remote-branch]
git checkout [branch-name]
git checkout -
git branch --set-upstream [branch] [remote-branch]
git merge [branch]
git cherry-pick [commit]
git branch -D [branch-name]
git push origin --delete [branch-name]
git branch -dr [remote/branch]
git remote prune origin
git checkout v2.0
git checkout -b devel origin/develop
git checkout -- README
git tag
git tag [tag]
git tag [tag] [commit]
git tag -d [tag]
git push origin :refs/tags/[tagName]
git show [tag]
git push [remote] [tag]
git push [remote] --tags
git checkout -b [branch] [tag]
七、查看信息
git status
git log
git log --stat
git log -S [keyword]
git log [tag] HEAD --pretty=format:%s
git log [tag] HEAD --grep feature
git log --follow [file]
git whatchanged [file]
git log -p [file]
git log -5 --pretty --oneline
git shortlog -sn
git blame [file]
git diff
git diff --cached [file]
git diff HEAD
git diff [first-branch]...[second-branch]
git diff --shortstat "@{0 day ago}"
git show [commit]
git show --name-only [commit]
git show [commit]:[filename]
git reflog
八、远程同步
git fetch [remote]
git remote -v
git remote show [remote]
git remote add [shortname] [url]
git pull [remote] [branch]
git push [remote] [branch]
git push [remote] --force
git push [remote] --all
九、撤销
git checkout [file]
git checkout [commit] [file]
git checkout .
git reset [file]
git reset --hard
git reset [commit]
git reset --hard [commit]
git reset --keep [commit]
git revert [commit]
git stash
git stash pop
git log 查看历史提交记录
git reset HEAD 回退到当前版本(取消暂存区的内容)
git reset --hard HEAD^ 回退到上个版本
git reset --hard HEAD^^ 回退到上上个版本
git reset --hard id(commit hash值) 回退到指定版本
git push origin HEAD --force 强推到远程:
git reset --hard origin/master 强推到远程并更新远程代码库
十、其他
git init # 初始化本地git仓库(创建新仓库)
git config --global user.name "xxx" # 配置用户名
git config --global user.email "xxx@xxx.com" # 配置邮件
git config --global color.ui true # git status等命令自动着色
git config --global color.status auto
git config --global color.diff auto
git config --global color.branch auto
git config --global color.interactive auto
git config --global --unset http.proxy # remove proxy configuration on git
git clone git+ssh://git@192.168.53.168/VT.git # clone远程仓库
git status # 查看当前版本状态(是否修改)
git add xyz # 添加xyz文件至index
git add . # 增加当前子目录下所有更改过的文件至index
git commit -m 'xxx' # 提交
git commit --amend -m 'xxx' # 合并上一次提交(用于反复修改)
git commit -am 'xxx' # 将add和commit合为一步
git rm xxx # 删除index中的文件
git rm -r * # 递归删除
git log # 显示提交日志
git log -1 # 显示1行日志 -n为n行
git log -5
git log --stat # 显示提交日志及相关变动文件
git log -p -m
git show dfb02e6e4f2f7b573337763e5c0013802e392818 # 显示某个提交的详细内容
git show dfb02 # 可只用commitid的前几位
git update-index --assume-unchanged config/index.js
git update-index --no-assume-unchanged config/index.js
解决方案:打开GIT日志,查看冲突的文件,把文件放入暂存区,重新同步一下代码
git stash
git pull
git stash pop
error: You have not concluded your merge (MERGE_HEAD exists).
hint: Please, commit your changes before merging.
fatal: Exiting because of unfinished merge.
解决方案
一: 保留本地的更改,中止合并->重新合并->重新拉取
git merge --abort
git reset --merge
git pull
二: 舍弃本地代码,远端版本覆盖本地版本,这步代码不可逆
git fetch --all
git reset --hard origin/master
git fetch