网站首页 > 技术文章 正文
- Git基本 命令
设置用户名和邮件
$ git config --global user.name "用户名"
$ git config --global user.email "邮箱"
git status 命令用于查看在你上次提交之后是否有对文件进行再次修改。git status -s可以获得简短的输出结果A表示成功
$ git status -s
A test.txt
git init 将文件夹初始化为git仓库
$ git init
Initialized empty Git repository in C:/Users/LDH/Desktop/wocao/.git/
git add . 将文件添加到暂存区
$ git add .
warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory
git commit -m “描述”将文件添加到版本库-m用来指定提交信息,这样提交只有一行-m "commit title" -m "commit description"
$ git commit -m "添加了test.txt文件"
[master (root-commit) 02959e8] 添加了test.txt文件
1 file changed, 2 insertions(+)
create mode 100644 test.txt
为什么要分add和commit两部?因为commit一次可以提交很多文件,所以可以多次add不同的文件
git diff test.txt可以查看文件被修改的具体内容
LDH@DESKTOP-F8BM77J MINGW64 ~/Desktop/wocao (master)
$ git diff test.txt
warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory
diff --git a/test.txt b/test.txt
index bb3f1f2..a938bbb 100644
--- a/test.txt
+++ b/test.txt
@@ -1,3 +1,4 @@
git is a control version
git is a free software
-wocao niubi
+wocao niubi
+wocoa
git log --oneline --graph --oneline查看历史记录的简介版本,--graph查看分支结构
$ git log --oneline --graph
* 028c201 (HEAD -> master) 修改了test.txt文件1
* cf6ce9f 修改了test.txt文件
* 02959e8 添加了test.txt文件
git reset --hard id回退到以前的版本有了--hard会直接修改工作区的内容不加--hard只是修改暂存区
$ git reset --hard cf6ce9f
HEAD is now at cf6ce9f 修改了test.txt文件
git reflog可以看到已经删除的提交命令
$ git reflog
cf6ce9f (HEAD -> master) HEAD@{0}: reset: moving to cf6ce9f
028c201 HEAD@{1}: commit: 修改了test.txt文件1
cf6ce9f (HEAD -> master) HEAD@{2}: commit: 修改了test.txt文件
02959e8 HEAD@{3}: commit (initial): 添加了test.txt文件
git checkout test.txt把test.txt文件在工作区的修改全部撤销回到最近一次git add 或git commit的状态
$ git checkout test.txt
Updated 1 path from the index
git reset HEAD test.txt将test.txt从暂存区撤销,放回工作区
$ git reset HEAD .
Unstaged changes after reset:
M test.txt
git rm 文件名称 git commit 从版本库中删除文件
$ git rm wocao.txt
rm 'wocao.txt'
$ git commit -m "删除wocao"
[master 36a7ff6] 删除wocao
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 wocao.txt
远程仓库
git remote -v查看是否有远程仓库
$ git remote -v
origin https://github.com/ldh55/test.git (fetch)
origin https://github.com/ldh55/test.git (push)
git remote rm origin1删除名为origin1的远程库
$ git remote rm origin1
- 第一步:创建sshkey id_rsa是私钥不能告诉任何人 id_rsa.pub是公钥可以告诉任何人 $ ssh-keygen -t rsa -C "2815843603@qq.com"
- 第二步:登陆github,打开设置,将id_rsa.pub中的内容添加到ssh key中
- 关联远程库,origin是远程库的名字,默认 $ git remote add origin https://github.com/ldh55/test.git
error: remote origin already exists. - 将本地库的内容推送到远程库上 $ git push origin master
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 347 bytes | 347.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/ldh55/test.git
101b930..c32db90 master -> master
从远程库克隆
$ git clone https://gitee.com/dong-hai-luo/niubi.git
Cloning into 'niubi'...
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (4/4), done.
git pull origin3 master
--allow-unrelated-histories先pull在 push pull = fetch+merge
$ git pull origin3 master --allow-unrelated-histories
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
From https://gitee.com/dong-hai-luo/life
* branch master -> FETCH_HEAD
Already up to date.
Merge made by the 'recursive' strategy.
分支管理
git checkout -b develop创建一个新的分支并切换到新的分支
$ git checkout -b develop
Switched to a new branch 'develop'
Git基本 命令
设置用户名和邮件
$ git config --global user.name "ldh"
$ git config --global user.email "2815843603@qq.com"
git status 命令用于查看在你上次提交之后是否有对文件进行再次修改。git status -s可以获得简短的输出结果A表示成功
$ git status -s
A test.txt
git init 将文件夹初始化为git仓库
$ git init
Initialized empty Git repository in C:/Users/LDH/Desktop/wocao/.git/
git add . 将文件添加到暂存区
$ git add .
warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory
git commit -m “描述”将文件添加到版本库-m用来指定提交信息,这样提交只有一行-m "commit title" -m "commit description"
$ git commit -m "添加了test.txt文件"
[master (root-commit) 02959e8] 添加了test.txt文件
1 file changed, 2 insertions(+)
create mode 100644 test.txt
为什么要分add和commit两部?因为commit一次可以提交很多文件,所以可以多次add不同的文件
git diff test.txt可以查看文件被修改的具体内容
LDH@DESKTOP-F8BM77J MINGW64 ~/Desktop/wocao (master)
$ git diff test.txt
warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory
diff --git a/test.txt b/test.txt
index bb3f1f2..a938bbb 100644
--- a/test.txt
+++ b/test.txt
@@ -1,3 +1,4 @@
git is a control version
git is a free software
-wocao niubi
+wocao niubi
+wocoa
git log --oneline --graph --oneline查看历史记录的简介版本,--graph查看分支结构
$ git log --oneline --graph
* 028c201 (HEAD -> master) 修改了test.txt文件1
* cf6ce9f 修改了test.txt文件
* 02959e8 添加了test.txt文件
git reset --hard id回退到以前的版本有了--hard会直接修改工作区的内容不加--hard只是修改暂存区
$ git reset --hard cf6ce9f
HEAD is now at cf6ce9f 修改了test.txt文件
git reflog可以看到已经删除的提交命令
$ git reflog
cf6ce9f (HEAD -> master) HEAD@{0}: reset: moving to cf6ce9f
028c201 HEAD@{1}: commit: 修改了test.txt文件1
cf6ce9f (HEAD -> master) HEAD@{2}: commit: 修改了test.txt文件
02959e8 HEAD@{3}: commit (initial): 添加了test.txt文件
git checkout test.txt把test.txt文件在工作区的修改全部撤销回到最近一次git add 或git commit的状态
$ git checkout test.txt
Updated 1 path from the index
git reset HEAD test.txt将test.txt从暂存区撤销,放回工作区
$ git reset HEAD .
Unstaged changes after reset:
M test.txt
git rm 文件名称 git commit 从版本库中删除文件
$ git rm wocao.txt
rm 'wocao.txt'
$ git commit -m "删除wocao"
[master 36a7ff6] 删除wocao
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 wocao.txt
远程仓库
git remote -v查看是否有远程仓库
$ git remote -v
origin https://github.com/ldh55/test.git (fetch)
origin https://github.com/ldh55/test.git (push)
git remote rm origin1删除名为origin1的远程库
$ git remote rm origin1
- 第一步:创建sshkey id_rsa是私钥不能告诉任何人 id_rsa.pub是公钥可以告诉任何人 $ ssh-keygen -t rsa -C "2815843603@qq.com"
- 第二步:登陆github,打开设置,将id_rsa.pub中的内容添加到ssh key中
- 关联远程库,origin是远程库的名字,默认 $ git remote add origin https://github.com/ldh55/test.git
error: remote origin already exists. - 将本地库的内容推送到远程库上 $ git push origin master
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 347 bytes | 347.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/ldh55/test.git
101b930..c32db90 master -> master
从远程库克隆
$ git clone https://gitee.com/dong-hai-luo/niubi.git
Cloning into 'niubi'...
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (4/4), done.
git pull origin3 master
--allow-unrelated-histories先pull在 push pull = fetch+merge
$ git pull origin3 master --allow-unrelated-histories
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
From https://gitee.com/dong-hai-luo/life
* branch master -> FETCH_HEAD
Already up to date.
Merge made by the 'recursive' strategy.
分支管理
git checkout -b develop创建一个新的分支并切换到新的分支
$ git checkout -b develop
Switched to a new branch 'develop'
猜你喜欢
- 2025-07-07 公司代码在内网的gitlab上,但是又想访问github,该怎么配置呢?
- 2025-07-07 Git分布式版本控制器常用命令和使用
- 2025-07-07 macbook 上安装git和将github作为托管服务器
- 2025-07-07 Jenkins实战(六)基于Jenkinsfile文件流水线发布
- 2025-07-07 手把手教你如何上传代码到gitee服务器
- 2025-07-07 从零打造自己的 国产鸿蒙(OpenHarmony)定制系统-完整可落地流程
- 2025-07-07 「工具」代码管理工具Git(git源代码管理工具)
- 2025-07-07 掌握git命令,图解一目了然(掌握git命令,图解一目了然的步骤)
- 2025-07-07 Git 2.47发布:引入增量多包索引、自动合并VS Code配置等
- 2025-07-07 Git安装避坑指南(git安装过程)
- 1509℃桌面软件开发新体验!用 Blazor Hybrid 打造简洁高效的视频处理工具
- 530℃Dify工具使用全场景:dify-sandbox沙盒的原理(源码篇·第2期)
- 493℃MySQL service启动脚本浅析(r12笔记第59天)
- 473℃服务器异常重启,导致mysql启动失败,问题解决过程记录
- 470℃启用MySQL查询缓存(mysql8.0查询缓存)
- 451℃「赵强老师」MySQL的闪回(赵强iso是哪个大学毕业的)
- 430℃mysql服务怎么启动和关闭?(mysql服务怎么启动和关闭)
- 427℃MySQL server PID file could not be found!失败
- 最近发表
- 标签列表
-
- c++中::是什么意思 (83)
- 标签用于 (65)
- 主键只能有一个吗 (66)
- c#console.writeline不显示 (75)
- pythoncase语句 (81)
- es6includes (73)
- windowsscripthost (67)
- apt-getinstall-y (86)
- node_modules怎么生成 (76)
- chromepost (65)
- c++int转char (75)
- static函数和普通函数 (76)
- el-date-picker开始日期早于结束日期 (70)
- js判断是否是json字符串 (67)
- checkout-b (67)
- localstorage.removeitem (74)
- vector线程安全吗 (70)
- & (66)
- java (73)
- js数组插入 (83)
- linux删除一个文件夹 (65)
- mac安装java (72)
- eacces (67)
- 查看mysql是否启动 (70)
- 无效的列索引 (74)