Git使用足迹

单个命令记录

将本地分支与远程的Origin的分支进行跟踪

Git push --set-upstream origin remote_branch

Commit操作

Git commit -m 'Commit msg'

push操作

远程已有Remote_branch分支并且已经关联本地分支local_branch,并且本地已经切换到local_branch分支

Git push

远程已有remote_branch分支但未关联本地分支local_branch,且本地分支已经切换到local_branch

Git push -u origin/remote_branch

远程没有remote_branch分支,本地已经切换到local_branch

Git push origin local_branch:remote_branch

本地分支与远程分支关联

查看当前分支与远程分支的关联

Git branch -vv

将当前本地分支与远程remote_branch分支进行关联

Git branch --set-upstream-to origin/remote_branch

删除本地分支与远程分支的关联

Git branch --unset-upstream

分支的删除

本地分支删除

Git branch -d local_branch

远程分支删除

Git push origin --delete 分支名

分支的查看

查看本地分支列表

Git branch

查看所有分支列表,包含本地和远程

Git branch -a

查看仓库当前的fetch,push地址

Git remote -v

清除无用的分支

Git remote prune origin

提交历史查看

查看所有提交历史(查看commitid和描述)

Git log

查看最近一次提交内容·

Git show

根据commid查看某个commit内容

Git show commitId

查看某个文件的修改记录

git log -- **/filename

撤销操作

撤销change

Git checkout -- 修改的文件地址(可通过git status查看本地分支状态)

撤销commit

Git reset --soft HEAD~2 撤回2个commit

代码合并

将本地代码更新与远程保持一致

Git merge origin/远程分支

关于修改.gitignore

我们修改一个某个文件或者文件夹git忽略
当这个文件已经被跟踪(未跟踪:从未被add或者commit的文件)需要忽略
需要先删除git数据库中对这个文件的追踪

Git rm --cache /fileName

查看设置代理

设置代理

Git config --global http.proxy 'socks5://127.9.9.1:1080'

Git config --global https.proxy 'socks5://127.0.0.1:1080'

查看代理

Git config --global --get http.proxy

Git config --global --get https.proxy

取消代理

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

修改仓库地址

修改命令

Git remote set-url origin [url]

先删除再添加

Git remote rm origin

Git remote add origin [url]

两个分支间的Commit合并

把B分支的76abcd commit合并到A分支,单个Commit的合并

Git cherry-pick 76abcd

把B分支的45abcd-76abcd commit合并到A分支,多个连续commit的合并

Git rebase --onto A 45abcd^

备注

  1. [理解]:命令中的-和--,-后面跟的是命令的缩写,--后面跟的是命令的全程。例如:-a和--all

操作流程

单独Clone远程某个分支代码,不更新所有分支相关信息

空文件夹,初始化拥有.git文件(创建结构)

Git init

配置当前git仓库地址

Git remote add origin 远程地址https://gitlab/…

更新远程指定分支代码到本地

Git fetch origin remote_branch

创建本地分支

Git checkout -b local_branch remote_branch

或者

 单独Clone远程某个分支代码

git clone -b 远程分支名称 远程地址

一些拉取代码的异常

Clone或者拉取代码报错The remote end hung up unexpectedly  (修改本地配置PostBuffer大小为500M或者更大)

git config --local http.postBuffer 524288000

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值