✍️
HOME
  • Introduction
  • Android
    • 基础
      • 文件读写
      • View
      • ViewGroup
      • Drawable
        • Shape
        • Selector
      • RecycleView
      • Databinding
    • Android Studio Git使用教程
    • Android Studio 版本更新历史
    • Maven 依赖管理
  • Linux
    • Linux系统安装
    • Linux 基础知识
    • Linux 服务器维护
    • 树莓派
    • Ubuntu
    • CDLinux
    • Shell Auto
    • 酸酸乳好喝
    • 后台运行
    • FRP
    • V +
  • Mac
    • Mac 版迅雷去广告
    • Homebrew 管理应用
    • 装机必备
  • Web
    • 前端环境搭建
    • 特殊需求
    • Python
  • Dev
    • Git 常用命令
    • Git submodule 和 subtree
    • GitBook
    • 软件问题处理
Powered by GitBook
On this page
  • 初始全局配置
  • 生成SSH key并测试连接
  • 断点续传
  • 远程
  • 同时push多个远程仓库
  • Diff & Merge
  • 配置p4merge作为Git的diff tool
  • 配置p4merge作为git的merge tool
  • 代理配置
  • http.proxy
  • core.gitProxy
  • ssh
  • 分支
  • 记录
  • 其他

Was this helpful?

  1. Dev

Git 常用命令

初始全局配置

git config --global user.name "wittyneko"
git config --global user.email "wittytutu@gmail.com"

生成SSH key并测试连接

ssh-keygen -t rsa -C "wittytutu@gmail.com"
# 测试链接
ssh -T git@github.com
ssh -T git@git.oschina.net

断点续传

git clone不支持断点续传,可以使用支持断点续传的git fetch

mkdir linux && cd linux
git init
git fetch git://mirrors.ustc.edu.cn/linux.git
git checkout FETCH_HEAD

远程

推送master分支到origin远程仓库

# git push [远程名] [本地分支]:[远程分支]
git push origin master

-u推送关联远程仓库,第一次提交到远程仓库

git push -u origin master

-f使用本地内容覆盖远程仓库

git push -f origin master
git push origin HEAD --force
git push origin HEAD:master --force

同时push多个远程仓库

Diff & Merge

配置p4merge作为Git的diff tool

git config --global diff.tool p4merge
git config --global difftool.p4merge.path "D:\Program\Perforce\p4merge.exe"
git config --global difftool.prompt false

配置p4merge作为git的merge tool

git config --global merge.tool p4merge
git config --global mergetool.p4merge.path "D:\Program\Perforce\p4merge.exe"
git config --global mergetool.prompt false

代理配置

1, https.proxy设置是无用的, 只需要设置http.proxy 2, socks5h://更好, 远端DNS

http.proxy

# 当前项目
git config http.proxy socks5://127.0.0.1:10808
git config http.proxy http://127.0.0.1:8088
git config http.proxy http://username:password@127.0.0.1:8088
# 全局
git config --global http.proxy socks5://127.0.0.1:10808
git config --global http.proxy http://127.0.0.1:8088
# 删除代理
git config --global --unset http.proxy
#只对github.com代理
git config --global http.https://github.com.proxy socks5://127.0.0.1:10808
git config --global --unset http.https://github.com.proxy)

# 关闭证书验证
git config --global http.sslVerify false

core.gitProxy

创建socks5_proxy_wrapper

  1. connect

    #!/bin/sh
    connect -S 127.0.0.1:8088 "$@"
  2. ncat

    #!/bin/sh
    /usr/bin/ncat --proxy 127.0.0.1:1081 --proxy-type socks5 "$@"
# 配置 gitProxy 
git config --global core.gitProxy '/opt/bin/socks5_proxy_wrapper'
git config --global core.gitProxy '/opt/bin/socks5_proxy_wrapper for git.kernel.org'
或 export GIT_PROXY_COMMAND
export GIT_PROXY_COMMAND="/opt/bin/socks5_proxy_wrapper"

ssh

1, ~/.ssh/config

Mac & Linux 编辑~/.ssh/config

ost github.com
    User git
    ProxyCommand nc -v -x 127.0.0.1:1086 %h %p
    # ProxyCommand socat - PROXY:127.0.0.1:%h:%p,proxyport=6667

Windows

Host github.com
    User git
    ProxyCommand connect -S 127.0.0.1:1086 %h %p

2, export GIT_SSH 创建 socks5_proxy_ssh

#!/bin/sh
ssh -o ProxyCommand="/path/to/socks5_proxy_wrapper %h %p" "$@"
export GIT_SSH="/path/to/socks5_proxy_ssh"

分支

查看分支

git branch -a

切换分支(切换前先提交更改)

git checkout master

查看比较远程分支和本地分支

git remote show origin

删除本地不存在的远程分支

git remote prune origin

记录

git rm --cached logs/xx.log 删除已提交文件记录 git log -v

其他

//添加gradle项目结构 git init git remote add gradle git@github.com:brady9308/gradle-frame.git git pull gradle master //不添加gradle项目结构 git init git remote add gradle git@github.com:brady9308/gradle-frame.git git pull gradle gradle //删除文件夹.git,清空版本管理信息 rm -rf .git //新建项目版本管理 git init git remote add origin git@github.com:brady9308/android-sample.git git push -u origin master

/////git command///// //(HEAD, HEAD^, HEAD~1) //HEAD 最近一个提交, HEAD^ 上一次 git push -u origin master //推送关联远程仓库 git push -f origin master //推送覆盖远程仓库 git push origin HEAD --force //推送覆盖远程仓库 git push origin HEAD:master --force //推送覆盖远程仓库

git branch gradle //创建分支 git checkout gradle //检出(切换)分支 git checkout -b gradle //创建并检出分支 git commit -a -m "create new branch" //创建新分支指针 git merge gradle //合并分支(回到主分支) git branch -d gradle //删除分支

git fetch origin //获取远程更新内容 git checkout --track origin/gradle //创建检出远程分支 git checkout -b gd origin/gradle //创建检出远程分支 git merge origin/gradle //合并远程分支 git push [远程名] [本地分支]:[远程分支] git push origin :gradle //删除远程分支 git push origin --delete gradle //删除远程分支 ` git reset <tag | commit_id | HEAD> //重置提交,commit和index git reset -soft //重置提交,commit git reset -head //重置提交,内容、commit和index git reset <文件名> //重置单个文件提交 git checkout -- <file name> //检出head指向版本的文件

git log --pretty=oneline 文件名 //查看commit历史 git log filename //查看commit历史 git log -p filename //提交的diff信息 git show commit_id filename //文件变化

PreviousPythonNextGit submodule 和 subtree

Last updated 4 years ago

Was this helpful?

终端下如何配置 git 使其可以同时 push 到两个远程仓库?
Helix Visual Merge Tool (P4Merge)
Git - 使用命令和P4Merge进行diff
git 设置和取消代理
Windows下git使用代理服务器的设置方法
[整理]为git 和ssh 设置socks5 协议的代理