Git入门

本文详细介绍了使用Git进行版本控制的基础知识,包括如何设置身份、常用命令的操作流程(如远程下载、添加文件、忽略文件、查看文件区别、删除文件等)、共享及更新项目的步骤(远程仓库的管理、分支的创建与切换、合并等),以及Git与SVN的对比。旨在帮助开发者掌握Git的基本操作,提高代码管理效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


1、初识GIT

1.了解系统环境变量

/etc/gitconfig

.gitconfig

 

2.设置身份

git config --help  [查看config帮助]

 

git config --global user.name "xdy"  [建一个全局的用户名]

 

git config --global user.email xdy@126.com  [创建邮箱]

 

3.设置编辑器(可选)

$ git config --global core.editor emacs

 

4.设置你的比较工具(可选)

$git config --global merge.tool vimdiff

 

5.检查你的配置(可选)

$ git config --list

 

6.帮助

$git help <verb>

 

$git <verb> --help

 

2、常用命令

2.1、远程下载

mkdir gittest1

 

cd gittest1

 

git init

 

远程下载:git clone git://github.com/git/hello-world.git

 

查看远程仓库的地址:git remote -v

 

2.2、添加文件

cd hello-world

 

echo "hello world" >> helloworld.txt

 

ls *.txt

 

git status[查看状态]

 

git add helloworld.txt 【添加文件】

 

git commit helloworld.txt -m "init helloworld"   [提交并添加日志]

 

2.3、忽略文件

echo "bin" > bin.dll

 

ls bin*

 

echo "bin.dll" > .gitignore

 

cat .gitignore

 

git add .

 

git commit -a -m "submit bin"

 

2.4、查看文件的区别

git diff

git diff --staged     比较workspace VS staged

git diff --cached 比较staged VS local repo

 

2.5、删除文件

git rm bin1.dll  删除文件

删除文件后找回文件办法:

git rm bin1.dll

ls *.dll

git reset HEAD bin1.dll

git checkout -- bin1.dll

ls *.dll

 

删除后提交 git commit -a -m "delete bin1.dll"

 

git log  查看日志

 

git whatchanged 查看发生了哪些改变

 

3、共享及更新项目

git remote 列出远程仓库

git fetch origin(从远程下载,不跟主版本合并,建立一个分支)

 

git pull origin(自动合并)

git push origin master    (master是本地的分)

git branch :列出分支

git format-patch origin/master打补丁

 

4、分支的管理

git branch 分支名字:建立分支

例如,建立一个名叫xdy的分支,命令为:git branch xdy

git checkout 分支名字:切换到分支上

 

合并merge

git merge merge branch1 to master HEAD branch1

 

另一种做法:

git checkout master

git pull .branch1

 

git tag -a Beta1 -m make beta1 :发布新版本

git tag Beta1切换回去Beta1

 

5、GitSVN的对比

5.1SVNGit在概念和特性上的区别


 5.2SVNGit在操作上的区别



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值