常用 git命令

来源:互联网 发布:如何自学程序员 编辑:程序博客网 时间:2024/05/17 18:47

检出分支

git clone -b dev git@gogs.taskwedo.com:PM/TechSharing.git ownbranchname

查看源

git remote git remote -v

更改1

git remote set-url origin xxxxx

更改2

git remote rm origin git remote add origin xxxxxxxxx

更改3

vim .git/config

新增源

git remote add originname originurl

不新增源只增 url

git remote set-url --add origin newurl

分支关联

git push -u origin remoteBranchgit branch --set-upstream-to=origin/remoteBranch

创建分支

git branch branchnamegit checkout -b branchname

合并分支

git checkout devgit merge --no-ff mergedBranch

删除分支

git branch -d localbranchgit branch -D localbranchgit push -d origin remotebranchgit push origin :dev

查看历史

git blame filename  #查看最后是谁修改的,每一行 git blame -L 160,+10 filenamegit log [--oneline|--graphy|--all] filenamegit log -p filename #查看详细历史修改,没有-p 只有提交记录,-p 后可以接数字,表明最近多少次提交历史

配置别名

git config --global alias.st statusgit config --global alias.ci commit

其他命令

git stash

配置文件地址

~/.gitconfig.git/config

设置
查看

git config --list

推送设置

git config --global push.default matching #名称匹配到的git config --global push.default simple # 仅当前分支对应

其他统一设置

git config --global user.name '123'git config --global user.email '123@qq.com'git config --global core.filemode false  # 忽略文件权限git config --global core.ignorecase false

windows 中

git config --global core.autocrlf false  # 换行符转换git config --global gui.encoding utf-8  # 避免 ui 乱码git config --global core.quotepath off   # 避免 git status 中文文件名乱码