Git极速入门-安装-命令讲解-搭建仓库

Git安装


1. Window 下载地址  https://gitforwindows.org/

2. Mac 下载地址  http://sourceforge.net/projects/git-osx-installer/

2. Linux 操作系统下的安装

// Ubuntu  
sudo apt-get install git
// CentOS  
sudo yum install git

3. 检验知否安装成功:出现 gitbash 命令行工具

git --version  // 查看git版本

Git基本命令


Git 完整命令手册地址:http://git-scm.com/docs

PDF 版命令手册:github-git-cheat-sheet.pdf

1. 初始化Git仓库

git init

2. 查看文件状态

git status 

3. Git 的3层结构

    working directory 工作区

    staging index 暂存区

    git directory(Repository) 版本库

3.1 从未被追踪的工作区提交到暂存区

git add file.txt  // 提交指定文件

git add .  // 提交全部文件

3.2 从暂存区提交到版本库

git commit file.txt

    如果出现:Please tell me how you are.

    则执行以下命令:

// 设置提交人信息
git config --global user.name "Your Name"
git config --global user.name "[email protected]"

// 查看 git 配置情况
git config --list

// 然后继续提交
git commit file.txt

// 查看提交的信息
git log

    如果出现错误:

// 则修改后重新
git add file.txt
git commit file.txt

3.3 从工作区直接提交到版本库

git commit -am 'remodified file.txt'

4. Git 文件的4种状态

untracked 未被追踪

modified 工作区修改了某个文件但是还没有添加到暂存区

staged 工作区修改的文件添加到了暂存区但是还没有提交到版本库

committed 表示数据被安全的存储在本地库中

5. Git 撤销操作

open here 点我查看

6. Git 文件删除

git rm filename // 删除工作区及暂存区中的该文件,相当于删除文件后执行 git add

git rm --cached filename // 在不小心将不需要追踪的文件添加到暂存区,想删除暂存区的文件但是不想删除工作区的文件

git rm -f filename // 当工作区或者暂存区文件修改了 glob 模式

git mv filename // 相当于 mv oldname newname → git rm oldname → git add newname

7. Git 分支基础

git branch // 查看分支

git branch branchname // 创建分支

git branch -m oldname newname // 修改分支名称

git checkout [-b] branchname // 切换分支

git branch -D branchname // 删除分支

8. Git 分支的合并

分支指针:HEAD指针指向当前工作的分支,在切换分支时指向新的分支

// 合并
// 1.提交代码及说明到版本库
git commit -m ' 说明文字 '

// 2.把自己分支的内容提交到远程自己的分支中
git push

// 3.切换到master分支
git checkout master

// 4.自己分支名称 把自己的分支和master分支合并
git merge

// 5.自己的分支和 master分支没有冲突,则快进式合并
Fast-forward
// 查看差异
git diff // 比较工作区与暂存区的文件差异
git diff --staged // 比较暂存区与版本库的文件差异

git diff 版本号 版本号 // 比较分之内的两个版本的差异(版本号选择 git log 中8-10位哈希值)(下图黄色为哈希值)

9. 储存的变更

git stash // 暂存当前正在进行的工作

git stash list // 将当前暂存的Git栈信息打印出来

git stash apply stash@num // git stash apply后不加名字,则应用最近一次的储存信息

git stash drop stash@num // git stash apply只是运用存储的信息,并不删除,drop命令删除它

10. Git 远程仓库的搭建

11. 切换远程仓库地址

方式一:修改远程仓库地址

git remote set-url origin Url  // 更换远程仓库地址,Url为新地址。

方式二:先删除远程仓库地址,然后再添加

git remote rm origin // 删除现有远程仓库

git remote add origin url // 添加新远程仓库

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

12. Git 帮助文档的使用

git help

git help command

欢迎大家提意见,本文章持续更新中。。。

猜你喜欢

转载自blog.csdn.net/weixin_44137575/article/details/107767550