[每周一更]-(第70期):常用的GIT操作命令

1、增删文件

复制代码
# 添加当前目录的所有文件到暂存区
$ git add .

# 添加指定文件到暂存区
$ git add <file1> <file2> ...

# 添加指定目录到暂存区,包括其子目录
$ git add <dir>

# 删除工作区文件,并且将这次删除放入暂存区
$ git rm [file1] [file2] ...

# 停止追踪指定文件,但该文件会保留在工作区
$ git rm --cached [file]

# 改名文件,并且将这个改名放入暂存区
$ git mv [file-original] [file-renamed]

把文件名 file1 添加到 .gitignore 文件里,Git 会停止跟踪 file1 的状态。

2、分支

复制代码
# 列出所有本地分支
$ git branch

# 列出所有本地分支和远程分支
$ git branch -a

# 新建一个分支,但依然停留在当前分支
$ git branch [branch-name]

# 新建一个分支,并切换到该分支
$ git checkout -b [new_branch] [remote-branch]

# 切换到指定分支,并更新工作区
$ git checkout [branch-name]

# 合并指定分支到当前分支
$ git merge [branch]

# 选择一个 commit,合并进当前分支
$ git cherry-pick [commit]

# 删除本地分支,-D 参数强制删除分支
$ git branch -d [branch-name]  命令:git branch -d 分支名

# 删除远程分支
$ git push [remote] :[remote-branch] 命令:git push origin --delete branch名

# 创建远程分支
(1)git checkout -b test 在当前分支下创建test分支,并进去到test分支
(2)git push origin test 将test分支推送到远程
(3)git branch --set-upstream-to=origin/test  test  //将本地分支 test 关联到远程分支 test中
(4)git branch -a  // 查看远程分支

# 同步本地和远程分支
(1)远程开好分支,本地 拉取,分支名test
git checkout -b test origin/test    //检出远程的feature-branch分支到本地
(2)建立分支管理关系
git branch --set-upstream-to=origin/humx humx
or
git branch -u origin/humx  humx 、 git branch -u origin/humx

结果:Branch 'humx' set up to track remote branch 'humx' from 'origin'.

3、提交

复制代码
# 提交暂存区到仓库区
$ git commit -m [message]

# 提交工作区与暂存区的变化直接到仓库区
$ git commit -a

# 提交时显示所有 diff 信息
$ git commit -v

# 提交暂存区修改到仓库区,合并到上次修改,并修改上次的提交信息
$ git commit --amend -m [message]

# 上传本地指定分支到远程仓库
$ git push [remote] [remote-branch]

### 4、拉取
# 下载远程仓库的所有变动 (Git only)
$ git fetch [remote]

# 显示所有远程仓库 (Git only)
$ git remote -v

# 显示某个远程仓库的信息 (Git only)
$ git remote show [remote]

# 增加一个新的远程仓库,并命名 (Git only)
$ git remote add [remote-name] [url]

# 取回远程仓库的变化,并与本地分支合并,(Git only), 若使用 Git-SVN,请查看第三节
$ git pull [remote] [branch]

# 取回远程仓库的变化,并与本地分支变基合并,(Git only), 若使用 Git-SVN,请查看第三节
$ git pull --rebase [remote] [branch]

# git clone https://xxx/xxx.git --depth 1
该命令只是拉取最近一直的提交记录,如果想拉取全部历史:  git pull --unshallow

# git仓库地址进行更新操作
git remote set-url origin git仓库地址

# git拉取某一个tag的分支仓库

git clone --branch v14.1.16 https://gitee.com/baijunyao/laravel-bjyblog.git

5、撤销

复制代码
# 恢复暂存区的指定文件到工作区
$ git checkout [file]

# 恢复暂存区当前目录的所有文件到工作区
$ git checkout .

# 恢复工作区到指定 commit
$ git checkout [commit]

# 重置暂存区的指定文件,与上一次 commit 保持一致,但工作区不变
$ git reset [file]

# 重置暂存区与工作区,与上一次 commit 保持一致
$ git reset --hard

# 重置当前分支的指针为指定 commit,同时重置暂存区,但工作区不变
$ git reset [commit]

# 重置当前分支的HEAD为指定 commit,同时重置暂存区和工作区,与指定 commit 一致
$ git reset --hard [commit]

# 新建一个 commit,用于撤销指定 commit
$ git revert [commit]

# 将未提交的变化放在储藏区
$ git stash

# 将储藏区的内容恢复到当前工作区
$ git stash pop

# 文件会回到暂存之前的状态
$ git reset HEAD

# 回退上一步制定位置
$ git reset --hard commitid

6、查询

复制代码
# 查看工作区文件修改状态
$ git status

# 查看工作区文件修改具体内容
$ git diff [file]

# 查看暂存区文件修改内容
$ git diff --cached [file]

# 查看版本库修改记录
$ git log

# 查看某人提交记录
$ git log --author=someone

# 查看某个文件的历史具体修改内容
$ git log -p [file]

# 查看某次提交具体修改内容
$ git show [commit]

# 查询远程仓库路径
git remote -v

# 本地分支和远程分支的关联关系
git branch -vv

# 查看具体的某一个commit信息
git show commitId
相关推荐
C++ 老炮儿的技术栈2 小时前
在C++ 程序中调用被 C编译器编译后的函数,为什么要加 extern “C”声明?
c语言·c++·windows·git·vscode·visual studio
二哈喇子!3 小时前
基于SpringBoot框架的网上购书系统的设计与实现
java·大数据·spring boot
云器科技4 小时前
大数据平台降本增效实践:四大典型场景的成本优化之路
大数据
B站计算机毕业设计超人4 小时前
计算机毕业设计Python知识图谱中华古诗词可视化 古诗词情感分析 古诗词智能问答系统 AI大模型自动写诗 大数据毕业设计(源码+LW文档+PPT+讲解)
大数据·人工智能·hadoop·python·机器学习·知识图谱·课程设计
Robin罗兵4 小时前
git使用教程2
git
德昂信息dataondemand7 小时前
销售分析中的痛点与解决之道
大数据·数据分析
jkyy20147 小时前
健康监测驾驶系统赋能:解锁新能源汽车健康出行新场景
大数据·人工智能·物联网·健康医疗
归去来?7 小时前
记录一次从https接口提取25G大文件csv并落表的经历
大数据·数据仓库·hive·python·网络协议·5g·https
bob_young7 小时前
Git LFS + Gerrit 配置+lfs-test-server(git lfs push总是提示输入https密码解决)
git·lfs
龙山云仓8 小时前
No131:AI中国故事-对话荀子——性恶论与AI约束:礼法并用、化性起伪与算法治理
大数据·人工智能·深度学习·算法·机器学习