git pull,fetch,merge
jgit 连接出现的异常
Git git = Git.cloneRepository().setURI(remotePath) //设置远程URI .setBranch(branch) //设置clone下来的分支 .setDirectory(new File(localPath)) //设置下载存放路径 .setCredentialsProvider(usernamePasswordCredentialsProvider) //设置权限验证 .call(); JGitInternalException 仓库初始化异常 org.eclipse.jgit.api.errors.JGitInternalException: Destination path "sql" already exists and is not an empty directory 远程URL连接错误 org.eclipse.jgit.api.errors.TransportException: URL:cannot open git-upload-pack 用户名,密码错误 org.eclipse.jgit.api.errors.TransportException: URL: not authorized org.eclipse.jgit.api.errors.TransportException: URL: not authorized 分支不存在 不报错
clone不能指定本地分支,只能和远程分支名一致,可结合checkout 一起使用
git clone -b 远程分支名 URL 本地目录 git clone -b master URL "./" git checkout -b 本地 origin/远程分支 git checkout -t origin/dev 该命令等同于: git checkout -b dev origin/dev
初始化 git init 添加远程仓库 git remote add origin URL 获取指定分支 git pull origin 远程分支:本地分支 git pull origin master:master
Git中从远程的分支获取最新的版本到本地
Git中从远程的分支获取最新的版本到本地有这样2个命令:
1. git fetch:相当于是从远程获取最新版本到本地,不会自动merge
git fetch origin master git log -p master..origin/master git merge origin/master
以上命令的含义:
首先从远程的origin的master主分支下载最新的版本到origin/master分支上
然后比较本地的master分支和origin/master分支的差别
最后进行合并
上述过程其实可以用以下更清晰的方式来进行:
git fetch origin master:tmp git diff tmp git merge tmp
从远程获取最新的版本到本地的tmp分支上
之后再进行比较合并
2. git pull:相当于是从远程获取最新版本并merge到本地
git pull origin master
上述命令其实相当于git fetch 和 git merge
在实际使用中,git fetch更安全一些
因为在merge前,我们可以查看更新情况,然后再决定是否合并