赞
踩
本地生成ssh Key
点击 Copy To Clipboard按钮复制ssh key内容,黏贴到github中,如下图
通常公司的开发环境都是windows,所以就会在IDEA里出现换行符为CRLF的问题。其实它本身没有问题,但是网上说,这个CRLF换行符放在Linux下,就会出现编译问题,因为Linux的换行符是LF。
查看配置
#读取system级别的配置:
git config --system --list
#读取global级别的配置:
git config --global --list
#读取local级别的配置:
git config --local --list
命令:
# 提交时转换为LF,检出时转换为CRLF (推荐)
git config --global core.autocrlf true #windows配置
# 提交检出均不转换
git config --global core.autocrlf false #linux配置
# 提交时转换为LF,检出时不转换
git config --global core.autocrlf input
#拒绝提交包含混合换行符的文件 (推荐)
git config --global core.safecrlf true
# 允许提交包含混合换行符的文件
git config --global core.safecrlf false
# 提交包含混合换行符的文件时给出警告
git config --global core.safecrlf warn
为了解决这个问题,在提交Git之前,在本地Git Bash对话框里,输入以下全局一次生效的命令:
修改配置
git config --global core.autocrlf true #windows配置
git config --global core.autocrlf false #linux配置
git config --global core.safecrlf true
如果把 autocrlf 设置为 false 时,那另一个配置项 safecrlf 最好设置为 ture
这样就可以让Git来对提交代码换行符的检测,关好最后一道门。
其它配置
color.ui=true
gui.encoding=utf-8
push.default=matching
core.autocrlf=true
core.safecrlf=true
core.quotepath=false
core.preloadindex=true
core.fscache=true
i18n.commitencoding=utf-8
i18n.logoutputencoding=gbk #支持中文
git账号密码输入错误无法clone
清除账户重新输入即可,清除命令为:
git config --system --unset credential.helper
#git pull <远程主机名> <远程分支名>:<本地分支名>
git pull origin master:master #拉取远程的master分支到本地master分支
git pull origin master:wy #拉取远程的master分支到本地wy分支
#push规则配置
git config --global push.default matching #安全,匹配分支,必须指定分支进行push
git config --global push.default current #不安全,但是使用方便
git push origin master:master #提交本地master分支到远程的master分支
git push origin master:wy #提交本地wy分支到远程的master分支
git push origin master:wy -f #强制提交本地wy分支到远程的master分支(覆盖方式)
git push origin wy:wy #提交本地wy分支到远程的wy分支(如果远程没有wy分支,则自动创建新分支wy)
git push origin :wy #删除远程的wy分支
1):将本地代码上传到本地仓库
进入项目文件夹xxxx
git init #初始化创建本地仓库
git add 1.file #添加1.file到stage区域
git commit -m "这次同步的内容" #提交到本地仓库,并做log记录
2):本地仓库连接远程gitlab地址
git remote add origin https://gitlab.com/xxxx.git #连接gitlab的项目地址
git push -u origin --all #上传本地代码 注意:如果是bitbucket网站,则需要先建立一个空仓库xxxx,否则会导致push失败
git push -u origin --tags #如果打了tag,上传tag
如果需要修改remote地址,则使用一下方法
git remote -v #查看remote已有的所有地址
git remote set-url origin https://ip_addr/xxx
#或者使用以下命令remove+add
git remote remove origin #删除项目的origin地址
git remote add origin https://gitlab.com/xxxx.git #连接gitlab的项目地址
参考:git submodule 完整用法整理
参考1:git submodule使用以及注意事项
参考2:Git Submodule使用完整教程
参考3:git中submodule子模块的添加、使用和删除
参考4:git submodule的使用
参考5:如何优雅的删除子模块(submodule)或修改Submodule URL
官方API命令:
git submodule [--quiet] add [<options>] [--] <repository> [<path>]
git submodule [--quiet] status [--cached] [--recursive] [--] [<path>…]
git submodule [--quiet] init [--] [<path>…]
git submodule [--quiet] deinit [-f|--force] (--all|[--] <path>…)
git submodule [--quiet] update [<options>] [--] [<path>…]
git submodule [--quiet] summary [<options>] [--] [<path>…]
git submodule [--quiet] foreach [--recursive] <command>
git submodule [--quiet] sync [--recursive] [--] [<path>…]
git submodule [--quiet] absorbgitdirs [--] [<path>…]
submodule常用命令
#假设prjA增加prjB子模块 #cd prjB #git init #git add b.txt #添加文件 #git commit -m "add b.txt" # case 1 local mode cd prjA git submodule add prjB #prjB为文件路夹绝对路径或者相对路径,会生成prjA/prjB文件夹和.gitmodules文件 git status -s # list status git commit -m "add submodule prjB" # case 2 remote mode cd prjA git submodule add <prjB_url> # 添加子项目,会生成prjA/prjB文件夹和.gitmodules文件 git submodule add <prjB_url> <path> # 添加子项目到指定目录 #url:替换为自己要引入的子模块仓库地址 #path:要存放的本地路径 git submodule add -b master <prjB_url> <path> #添加子项目指定分支到指定目录 # 在.gitmodules 文件中设置分支 # 其中 <path> 是主目录中安装的子目录的名称, stable 是对应要设置的分支名称 git config -f .gitmodules submodule.<path>.branch stable git status -s # list status git commit -m "add submodule prjB" cd prjB git pull # pull new version of submodule prjB
使用submodule模式,仅需要在子模块目录下操作,命令同正常版本控制命令一样,可以pull,push等操作
建议 .gitmodules 文件中添加 ignore = all内容,子模块的更新不受版本控制(常用管理方式,开放型)
子模块开发初期推荐使用case 2模式,待子模块开发稳定之后,推荐改用case 1模式
#假设prjA增加prjB子模块 cd prjA git init git add a.txt #添加文件 git commit -m "add a.txt" cd prjB git init git add b.txt #添加文件 git commit -m "add b.txt" cd prjA git submodule add prjB #prjB为文件路夹绝对路径或者相对路径,会生成prjA/prjB文件夹和.gitmodules文件 git commit -m "add submodule prjB" cd prjB #b.txt进行修改操作 git add b.txt #添加文件 git commit -m "second" cd prjA git status -s #发现prjB没有对应更新 git submodule update --remote #需要update子模块remote版本才能获取最新的prjB #或者 cd prjB git pull git status -s #此时发现prjB有更新 #策略1. prjB的更新受版本控制 安全管理方式 git add prjB git commit -m "update submodule prjB" #策略2. prjB的更新不受版本控制 常用管理方式,开放型 vi .gitmodules #添加 ignore = all内容即可 git add .gitmodules git commit -m "modified .gitmodules" git submodule update --remote git status -s #发现prjB跟新状态被过滤掉,没有显示文件状态不同
clone/update远程仓库
git clone xxxxx
git submodule init #或者 git submodule init --recursive 有多个子模块
git submodule update #或者 git submodule update --recursive 有多个子模块
#或者一条命令 git submodule update --init --recursive 有多个子模块
git submodule foreach "git log" #查看子模块最新log
git submodule foreach "git status" #查看子模块最新状态
git 是不支持空文件夹版本管理的,可以选择在空文件夹中添加.keep文件的方式解决
在项目中使用git管理代码后,有些时候会创建很多不同名称的分支,以此区分各个分支代码功能。 而随着代码的合并,以前的分支就可能不再需要保存了,所以就要对没有用的分支进行删除,包括紧急回滚时从中抽取某一个版本记录所创建的临时分支。 这时候就可以使用下面的命令:
#1.列出本地分支:
git branch
#2.删除本地分支:
git branch -D BranchName
#其中-D也可以是--delete,如:
git branch --delete BranchName
#3.删除本地的远程分支:
git branch -r -D origin/BranchName
#4.远程删除git服务器上的分支:
git push origin -d BranchName
#其中-d也可以是--delete,如:
git push origin --delete BranchName
注意:git命令区分大小写,例如-D和-d在不同的地方虽然都是删除的意思,并且它们的完整写法都是–delete,但简易写法用错大小写会执行失败。
参考:https://www.cnblogs.com/VAllen/p/git-remote-delete-origin-branches.html
#本地分支重命名
git branch -m old_name new_name
#远程分支重命名
git push --delete origin old_name #先删除远程分支old_name
git branch -m old_name new_name #重命名本地分支old_name为new_name
git push origin new_name #推送本地分支new_name到远程仓库,即重命名远程分支
# git_terminal_show_branch.sh
echo -e "\n#git\nfunction parse_git_dirty {\n [[ \$(git status 2> /dev/null | tail -n1) != \"cache is None\" ]] && echo \"*\"\n}" >> ~/.bashrc
echo -e "function parse_git_branch {\n git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e \"s/* \(.*\)/[\1\$(parse_git_dirty)]/\"\n}" >> ~/.bashrc
echo -n "export PS1='\\[\\033[01;32m\\]\\u@\\h\\[\\033[00m\\]:\\[\\033[01;34m\\]\\W\\[\\e[1;36m\\]\$(parse_git_branch)\\[\\e[0m\\]\$ '" >> ~/.bashrc
Coding远程仓库地址变了,本地git仓库地址如何更新为最新地址
方法有三种:
#1.修改命令
git remote set-url origin https://github.com/xx/xx1.git
#2.先删后加
git remote rm origin
git remote add origin [url]
#3.直接修改config文件
submodule的Coding远程仓库地址变了,本地git的submodule仓库地址如何更新为最新地址
#0.查看submodule信息 git config --file=.gitmodules -l # 显示结果示例如下 submodule.abc.path=soccer submodule.abc.url=https://123/abc.git submodule.abc.ignore=all ... #1.修改命令 vim .gitmodules #直接修改 url=https://456/abc.git vim .git/config #直接修改 url=https://456/abc.git #2.同步配置信息 git submodule sync #3.保存配置信息 git add .gitmodules git commit -m "update submodule url" #3.更新submodule数据 $ git submodule update
https://learngitbranching.js.org/?locale=zh_CN
此方法适用于未commit的情况
git reset
git checkout filename
看区别的话,使用默认的git diff进行查看,通过嵌入+++和—标记到原文件中,这样浪费了右侧的屏幕空间,也不太直观。还是左右对比来的直观点此方法适用于未commit的情况
# 安装icdiff
sudo apt-get install icdiff
# icdiff使用命名
git icdiff
效果如下
git log #找到需要合并的节点的前一个结点
git rebase -i commitID #commitID为合并前节点hash值
#修改记录->按esc退出编辑模式->:wq保存新修改log信息->完成
#如果中间出现rebase问题(某些文件有进程占用导致rebase失败或者警告等信息)
git rebase --abort #先撤销rebase操作,然后关闭文件相关进程,再重新rebase操作
# setp1. 在本地库中清除文件/文件夹 #永久删除文件 git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch path-to-your-remove-file' --prune-empty --tag-name-filter cat -- --all #永久删除文件夹 git filter-branch --force --index-filter 'git rm -rf --cached --ignore-unmatch path-to-your-remove-path' --prune-empty --tag-name-filter cat -- --all # step2. 推送修改后的状态到远程仓库 # 强制方式push到远程仓库 git push origin master --force # step3. 清理和回收空间 rm -rf .git/refs/original/ git reflog expire --expire=now --all git gc --prune=now git gc --aggressive --prune=now # 现在看看你的.git目录文件大小是不是变小了!
path-to-your-remove-file就是需要删除的文件相对路径
path-to-your-remove-path就是需要删除的文件夹相对路径
git update-index --chmod +x filename.sh
# 1. 普通merge
git checkout master
git merge opt #然后进行冲突解决进行合并
# 2. 强制opt merge到 master
git checkout opt
git merge -s ours master
#指定文件撤销
git reset <file> #撤销file文件add到缓存区
#所有文件撤销
git reset HEAD #取消所有更改
#1.切换到新的分支
git checkout --orphan latest_branch
#2.缓存所有文件(除了.gitignore中声明排除的)
git add -A
#3.提交跟踪过的文件(Commit the changes)
git commit -am "commit message"
#4.删除master分支(Delete the branch)
git branch -D master
#5.重命名当前分支为master(Rename the current branch to master)
git branch -m master
#6.提交到远程master分支 (Finally, force update your repository)
git push -f origin master
#通过以上几步就可以简单地把一个Git仓库的历史提交记录清除掉了
git init git add file-name git add . git add -u git add -v git log git log --oneline git log --oneline --graph git ls git ls-files git commit git commit -m "log message" git commit --amend git commit --amend -m "log message" git commit --amend --no-edit #洁癖者建议使用该提交命令 git push -u orgin master git push -u --all git push --tag --all git push origin master:master git push origin master:opt git push --force git push -f git pull git pull origin master:master git pull origin master:opt git pull --force git pull -f git rebase -i commitID
#问题描述:在github上下载一个开源项目,本地git环境已经建好,之前也用过,本地仓库已经建好。当执行git clone https://github.com/openstf/stf.git 命令的时候,一直提示无法访问
#解决方法:
git clone https://github.com/openstf/stf.git 修改如下
git clone git://github.com/openstf/stf.git 即可解决
#这货由 Git 官方出品,在安装时就会向你兜售“换行符自动转换”功能,估计大多数人在看完华丽丽的功能介绍之后会毫不犹豫地选择第一项(自动转换)。请千万抵挡住诱惑,选择最后一项(不作任何手脚)。如果你已经做出了错误的选择,也不需要重新安装,可以直接使用命令行来修改设置。很简单,直接打开这货自带的命令行工具 Git Bash,输入以下命令,再敲回车即可:
git config --global core.autocrlf false
主要是由于git版本升级之后的ssl协议版本也进行了相应的升级,导致当前低版本的git无法正常工作
解决方法:
升级当前的git客户端即可,下载地址:https://git-scm.com/downloads
#解决方案:
git config --global core.quotepath false
set output-meta on
set convert-meta off
最后,git bash 终端输入命令:
git config --global core.quotepath false # 显示 status 编码
git config --global gui.encoding utf-8 # 图形界面编码
git config --global i18n.commitEncoding utf-8 # 提交信息编码
git config --global i18n.logoutputEncoding utf-8 # 输出 log 编码
export LESSHARESET=utf-8
git config --unset core.bare
原因:
是Git的Http代理的问题,Git支持三种协议:git://、ssh:// 和 http://,本来push的时候应该走ssh隧道的,但是因为设置了http代理,所以就走了http的代理,于是就提交不了了。
#输入以下命令,回车即可
git config --unset http.proxy
#或者全局配置
git config --global --unset http.proxy
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。