git
常用命令
设置全局账号密码
git config --global user.name "你的GitHub用户名" git config --global user.email "你的GitHub注册邮箱"
取消全局账号密码
git config --global --unset user.name git config --global --unset user.email
查看全局配置
git config --global --list
初始化仓库
git init
提交到暂存库、版本库
git add file git commit -m "add messages!"
查看版本记录
git log
回退版本
git reset --hard HEAD~2
查看
git
操作历史命令git reflog
查看版本维护状态
git status
查看当前工作区和版本库最新区别
git diff HEAD -- readme.txt
撤销操作
git checkout -- readme.txt 【未提交到暂存库,撤销本地修改】 git rest HEAD readme.txt 【清空暂存库】
删除操作
git rm readme.txt git commit -m "delete readme.txt"
添加远程库
git remote add origin http://xxx.xxx.xxx.xxx:xx/git/root/aa.git git remote origin git@github.com:MyGithubId/aa.git
推送本地库内容到远程库
git push -u origin master git push origin master
重命名文件夹
git mv -f oldfolder newfolder git add -u newfolder git commit -m "changed the foldername"
从远程仓库获取最新的到本地
git pull
这样做比较危险,可能有很多冲突或者出错的地方,所以一般是这样操作
git fetch origin master:temp 【把远程orgin仓库的master分支下载到本地temp分支】 git diff temp 【比较本地代码和远程下来代码的差异】 git merge temp 【合并temp分支到本地的master分支】 git branch -d temp 【删除temp分支】
查看远程仓库
url
地址git remote -v
修改仓库
url
地址# 方法一: git remote set-url origin URL // URL为需要更换的新地址 # 方法二: git remote rm origin // 删除现有远程仓库 git remote add origin url // 添加新的远程仓库
提交出现
errno 10053
## 报下面错误: git push origin master fatal: unable to access 'https://github.com/lmwings/hexo-source.git/': OpenSSL SSL_read: Connection was aborted, errno 10053 # 解决方法: # 设置上次大小限制 git config http.postBuffer 524288000 git config --global http.sslVerify false # 查看配置是否生效 git config -l
提交报
TaskCanceledException encountered
git config –global credential.helper manager # 再提交
查看暂存区内容的命令
git ls-files
删除暂存区内存的命令
git rm --cached 文件名
冲突解决方法
很多时候,仓库中的修改和本地的修改有冲突的地方,一般会报下面的错误;git pull error: Your local changes to the following files would be overwritten by merge: .obsidian/workspace Please commit your changes or stash them before you merge. Aborting
怎么样解决这个冲突呢?
方法一:合并修改
先使用下面的命令做备份,
```shell
# 备份当前的工作区内容;从最近一次的提交中读取相应内容;即保证工作区和上一次提交的内容相同; 然后保存到Git栈中
git stash
# 提交到暂存区中
git commit
# 从Git栈中读取最近一次内容,并恢复到工作区
git stash pop
然最后使用git diff
查看自动合并的情况,并做对应的修改。
方法二:放弃本地修改,直接覆盖
git reset --hard
git pull
查看
Git
栈所有备份git stash list
清空
Git
栈git stash clear
解决文件冲突
提交到仓库中出现如下错误error: Pulling is not possible because you have unmerged files. hint: Fix them up in the work tree, and then use 'git add/rm
' hint: as appropriate to mark resolution and make a commit. fatal: Exiting because of an unresolved conflict. 一般这种就是存在文件冲突,常常用如下方法解决
git add -u git commit -m "" git pull