赞
踩
目录:
1.git环境配置
Git 简介:
Git 环境验证:
git --version
。git --version
。2.git工作流程
Git 基本概念:
Git 工作流程:
3.git常用命令
基于 Git 的远程仓库:
Git 同步命令:
克隆远程仓库:
git clone <url>
远程连接方式 特点
- HTTPS 连接使用给定 URL 即可 clone,在 push 时验证用户名和密码。
- SSH 连接 需要提前添加 SSH Key,在 push 时不需要输入用户名,配置 SSH 时设置了密码才需要输入密码。
HTTPS 连接:
git config --global user.name "your name"
git config --global user.email "your_email@youremail.com"
git config --global --list
SSH 连接:
拉取远程仓库:
git pull
初始化仓库:
git init
git remote add origin <url>
Git 修改命令:
跟踪新文件:
git add <file>/<directory>
# 跟踪某个文件
git add new_file.txt
# 跟踪当前目录下所有文件
git add .
提交更新:
git commit -m "comments"
推送到远程仓库:
git push
Git 常用调试命令:
检查当前文件状态:
git status
查看已暂存和未暂存的修改:
git diff
git diff --staged
撤销操作:
git checkout <file>
git reset HEAD <file>
cat readme.txt
1234
update1
update2
update3
git checkout readme.txt
cat readme.txt
1234
update1
update2
git reset HEAD file.txt
git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
file.txt
nothing added to commit but untracked files present (use "git add" to track)
移除文件:
git rm -f <file>
git rm --cached <file>
忽略文件:
.gitignore
文件。4.gitlab实战
GitLab 帐号:
配置公钥:
5.gitlog分析与检索
Git Log 分析:
git log
Git Log 检索:
git log --since='2023-02-02 00:00:00'
git log --author='feier'
git log --grep='update'
6.分支管理策略
分支管理:
创建分支:
git branch 分支名
git checkout -b 分支名
查看分支:
git branch
git branch -r
git branch -a
切换分支:
git checkout 分支名
删除分支:
git branch -d 分支名
7.git合并与冲突
分支合并应用场景:
合并分支:
git merge 其他分支 本分支
git rebase 其他分支
什么是冲突?
解决冲突:
git add .
添加到暂存区。git commit -m '提交说明'
提交到本地仓库,完成合并。git push
提交到远程仓库。Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。