Git是一款免费、开源的分布式版本控制系统,广泛应用于软件开发领域。随着开源和云计算的发展,Git已经成为了开发者必备的工具之一。本文将为大家介绍Git在Windows、Mac和Linux三个平台上的安装和配置方法,带你一次性搞定Git环境
在 git 诞生之前,Torvalds 选择使用 BitKeeper 进行 Linux 版本管理。BitKeeper 是一个闭源的商业软件,这个决定长期受到社区的质疑和争议。
2005 年,一位 Linux 开发成员 Andrew(Samba 协议之父)写了一个可以连接 BitKeeper 仓库的外挂,因此 BitMover 公司(BitKeeper 持有者)认为他反编译了 BitKeeper。BitMover 决定中止 Linux 免费使用 BitKeeper 的授权。最终 Linux 团队与 BitMover 磋商无果,Torvalds 决定开发自己的版本管理系统。
十天后,git 诞生了
你没有看错。git 从开始到诞生,Torvalds 这位天才只用了 10 天的时间。
Git是目前世界上最先进的分布式版本控制系统。
1.官网地址
https://git-scm.com/
2.淘宝镜像地址
https://npm.taobao.org/mirrors/git-for-windows/
下载之后无脑下一步安装即可,安装完毕就可以使用
3.git包讲解
Git Bash:Unix与Linux风格的命令行,使用最多,推荐最多
Git CMD:Windows风格的命令行
Git GUI:图形界面的Git,不建议初学者使用,尽量先熟悉常用命令Git 配置
$ git config -l
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=openssl
http.sslcainfo=D:/APP/git/Git/mingw64/ssl/certs/ca-bundle.crt
core.autocrlf=true
core.fscache=true
core.symlinks=false
core.editor="D:\\APP\\notepad++\\notepad++.exe" -multiInst -notabbar -nosession -noPlugin
credential.helper=manager
$ git config --system --list
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=openssl
http.sslcainfo=D:/APP/git/Git/mingw64/ssl/certs/ca-bundle.crt
core.autocrlf=true
core.fscache=true
core.symlinks=false
core.editor="D:\\APP\\notepad++\\notepad++.exe" -multiInst -notabbar -nosession -noPlugin
credential.helper=manager
#相关配置文件位置
D:\APP\git\Git\etc\gitconfig
$ git config --global --list
user.name=MM
user.email=11816495+he_ber@user.noreply.gitee.com
#相关配置文件路径
C:\Users\user\.gitconfig
git config --global user.name "MM"
git config --global user.email 11816495+he_ber@user.noreply.gitee.com
1、在工作目录中添加、修改文件;file
2、将需要进行版本管理的文件放入暂存区域;git add
3、将暂存区域的文件提交到git仓库。git commit
因此,git管理的文件有三种状态:已修改(modified),已暂存(staged),已提交(committed)
创建本地仓库的方法有两种:
# 使用当前目录作为 Git 仓库,我们只需使它初始化。
git init
$ git init
Initialized empty Git repository in C:/Users/user/Desktop/git_init/.git/
该命令执行完后会在当前目录生成一个 .git 目录。
git clone <url>
git clone https://gitee.com/he_ber/he_ber.git
git status filename
git add .
git commit -m "说明"
有些时候我们不想把某些文件纳入版本控制中,比如数据库文件,临时文件等
在主目录下建立”.gitignore”文件,此文件有如下规则:
#为注释
*.txt #忽略所有 .txt结尾的文件
!lib.txt #但lib.txt除外
/temp #仅忽略项目根目录下的TODO文件,不包括其它目录temp
build/ #忽略build/目录下的所有文件
doc/*.txt #会忽略 doc/notes.txt 但不包括 doc/server/arch.txt
官网:https://gitee.com/
git clone https://gitee.com/he_ber/git_study.git
git add filename
git commit -m "这是第一版"
git push
可以理解多线程:主线程在走,不影响子影响。它们是平行,互不影响。但是,他们可以进行合并。在合并的时候就需要做一些处理了。
# 列出所有本地分支
git branch
# 列出所有远程分支
git branch -r
# 新建一个分支,但依然停留在当前分支
git branch [branch-name]
# 新建一个分支,并切换到该分支
git checkout -b [branch]
# 合并指定分支到当前分支
$ git merge [branch]
# 删除分支
$ git branch -d [branch-name]
# 删除远程分支
$ git push origin --delete [branch-name]
$ git branch -dr [remote/branch]
如果同一个文件在合并分支时都被修改了则会引起冲突:
解决引起冲突办法::
master主分支应该非常稳定,用来发布新版本,
一般情况下不允许在上面工作,工作一般情况下在新建的dev分支上工作,工作完后,代码稳定了,再合并到主分支上来。
比如上要发布,或者说dev分支代码稳定后可以合并到主分支master上来。
评论