console.|

随枫而动

园龄:3年10个月粉丝:0关注:15

Git使用

什么是Git

Git是一个分布式版本控制系统,可以追踪文件的变化并协调多人在相同文件上的编辑工作。它允许用户在不同版本之间切换、创建新的分支、将不同版本的代码合并在一起等操作,有效管理软件开发中的代码。
image

配置

查看当前项目的Git配置信息

git config --list
image

设置当前主机的Git的账户名、邮箱地址、Git仓库远程地址

git config --global user.name "Your Name"
git config --global user.email "email@example.com"
git remote set-url origin https://gitee.com/xx/xx.git

拉取

在远程拉取代码

git clone https://github.com/liduchang/redis
或者
git pull https://github.com/liduchang/redis
image

项目

初始化Git项目

git init /code

推送

推送代码过程

将a.txt添加进暂存区
git add a.txt
查看代码提交信息
git log
git log --oneline
git log --pretty=oneline

git log
image

将当前目录中的所有代码添加进暂存区

git add .

代码添加进本地仓库 -m "提交信息"

git commit -m "增加了用户功能"

代码推向远程仓库

git push

代码分支架构

image

回滚

回到过去获取数据后,必须回到现在
显示HEAD指针移动的轨迹 HEAD{0} 是指针当前所在的位置
git reflog

移动到HEAD指针到指定版本

git reset --hard 58b6841 #版本号

分支

查看远程的所有分支列表并显示当前分支

git branch -a
image

查看本地的所有分支列表并显示当前分支

git branch -v
image

创建分支

git branch aaa
image

切换到指定分支

git checkout aaa
image

合并

将tow分支内容合并到master分支

1、切换到你所在分支master:git checkout master
2、git merge tow
3、将本地内容push到master分支:git push

常见的问题

fatal: unable to access 'https://github.com/xxx/******.git/': Failed to connect to github.com port 443 after 21090 ms: Couldn't connect to server

1、连接github出现错误

github在国外,从上面拉取代码时,连接github出现错误

解决方案

前提条件,【有梯子】
1.查看本机系统端口号
image
2、设置git端口号和上面的端口号保持一致(我的是10809)
git config --global http.proxy 127.0.0.1:10809
git config --global https.proxy 127.0.0.1:10809

本文作者:在这颗星球上的旅行

本文链接:https://www.cnblogs.com/fcloud/p/18672736

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   随枫而动  阅读(9)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 Love Theme Audio artist
  2. 2 吹梦到西周 Audio artist
Love Theme - Audio artist
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.