Git
Git常用命令
Git命令
git add .
添加至暂存区git rm --cached filename1 filename2 ...
撤回暂存区的文件git ls-files
查看add内容git rm -r --cached
清除add在缓存里面的内容git rm --cached <文件路径>
清除add在缓存里面的某个文件(不删除物理文件,仅将该文件从缓存中删除)git commit -a -m "…"
提交改变的文件,-a提交所有改变,-m附加注释git push origin master
将本地分支岁送到服务器上的master分支中,origin是服务器地址,master是自己的分支名git push <远程主机名> <本地分支名>:<远程分支名>
将本地分支送到服务器上的远程分支中git init --bare
初始化仓库,初始化终端仓库时需要加--bare
git pull origin master
将服务器的版本同步至本地,origin是服务器地址,本地分支名与远程分支名均为mastergit pull <远程主机名> <远程分支名>:<本地分支名>
将服务器的远程分支版本同步至本地的分支中git status
查看仓库与本地的状态git diff +文件
查看文件的修改内容git remote add origin /Z/guihua/share…
添加远程库的路径的"快捷方式",origin = Z:/guihua/share…git remote -v
查看远程库信息git remote rm name
删除远程仓库git remote add <name> <URL>
使用指定字符串name来代替整个URLgit remote rename old new
更新仓库名,从old更新到newgit log
查看版本的历史记录git log --oneline --graph --all
以图像(graph)的形式,简短(oneline)的显示所有(all)版本信息git reset --hard HEAD^
git reset --hard 版本号
回溯到上个版本/指定版本(版本号使用git log可查询)
- 首次提交代码时:
git config --global user.name "runoob"
git config --global user.email "runoob@email.com"
git branch <branchname>
创建分支名git branch
查看已存在分支和当前分支git branch -d/D <branchname>
删除本地分支(之前应checkout切换到其他分支)git checkout <branchname>
切换分支名git checkout -b <branchname>
创建并切换到该分支git merge branch
将branch分支合并到当前分支中git merge --abort
退出合并,不解决合并冲突
pull
-
首次下拉远程版本库时,需要初始化git库。
git init
-
添加远程库路径的“快捷方式”
git remote add origin /z/guihua/share/InSAR/LandSARGitRepostory
origin
为任意字符串,可根据情况修改origin后面输入远程库的真实路径
-
下拉远程git库
git pull origin master
git pull origin origin_branch:local_branch
origin
也可以使用真实路径替换对比本地分支和远程分支相同的情况,可以直接填写一个
master
即可,但若遇到远程库分支与本地分支不同的情况则需要输入branch_a:branch_b
。
clone
使用clone的方式下拉远程库,方法大致与pull相同,但不能使用字符替换地址,必须使用真实路径
git clone /z/guihua/share/InSAR/LandSARGitRepostory
Connection was reset
fatal: unable to access 'https://github.com/dev-cafe/cmake-cookbook.git/': OpenSSL SSL_read: Connection was reset, errno 10054
这是服务器的SSL证书没有经过第三方机构的签署,所以报错。
解决方法:
git config --global http.sslVerify "false"
Failed to connect to github
fatal: unable to access 'https://github.com/dev-cafe/cmake-cookbook.git/': Failed to connect to github.com port 443: Timed out
尽管此时,我们的电脑已经可以翻墙了,git clone却不行,原因在于git 也需要配置代理:
git config --global http.proxy http://127.0.0.1:7890
或使用其他地址:
git config --global https.proxy http://127.0.0.1:7890
git config --global http.proxy http://127.0.0.1:9666