git

git常用操作个人总结

Posted by Remilia Scarlet on August 17, 2020

git 放弃本地修改 强制更新

#第一种方法
git fetch --all
git reset --hard origin/master
git fetch #只是下载远程的库的内容,不做任何的合并 git reset 把HEAD指向刚刚下载的最新的版本

#第二种方法
git checkout .
git clean -df

在dev分支工作时合并主分支的新内容

#如果没有冲突
git pull master

#如果有冲突,则先保存当前修改,合入完成后再解决冲突
git stash
git pull master
git stash pop

git设置代理

#设置本仓库的代理
git config --local http.proxy 'socks5://127.0.0.1:1080'
git config --local https.proxy 'socks5://127.0.0.1:1080'

#直接设置某个站点的代理
git config --global http.https://github.com.proxy 'socks5://127.0.0.1:1080'
git config --global https.https://github.com.proxy 'socks5://127.0.0.1:1080'

git取消代理设置

git config --global --unset http.proxy
git config --global --unset https.proxy

修改缓冲区的方法提高克隆速度(非代理)

git config --global http.postBuffer 524288000

只下载最新的代码

git clone --depth=1 https://github.com/bcit-ci/CodeIgniter.git

查看一个远程仓库的url

git remote get-url origin

修改远程仓库在本地的简称

git remote rename origin github

添加一个远程url

git remote add gitee http://your-url

git追踪某一行的提交记录

git blame file
git blame -L 3,10 file
git show commitid

git revert回退版本

git revert HEAD  撤销前一次的commit
git revert HEAD^  撤销前前一次的commit
git revert <commitid>  撤销某一次的改动

从git log中查找某个文件中的某个字段在哪一个commit中修改

git log -S "要搜索的字段" -- <文件名>

从另外一个分支cherry pick最新N笔提交

{ git log --format=format:%H feature -n N; echo; } | tac | sed '$d' | xargs git cherry-pick

合并最新的N笔提交

git rebase -i HEAD~N

然后将除了第一个提交之外的所有提交从pick改为squashs


| 访问量: