Git常用命令

Git常用命令

1.仓库
shell 复制代码
#当前目录新建一个代码库
git init
#新建一个目录,将其初始化为代码库
git init [exercise]
#拉取一个远程项目和整个代码历史
git clone [url]
2.配置
shell 复制代码
#显示git的配置
git config --list
#编写git的配置文件
git config -e [--global]
#设置提交时的用户信息
git config [--global] user.name "xwz"
git config [--global] user.email "88888888@email"
3.增加删除文件
shell 复制代码
#添加指定文件到暂存区
git add [file1] [file2]
#添加指定目录及子目录到暂存区
git add [dir]
#添加当前目录所有文件到暂存区
git add .

#删除工作区文件,并且将这次删除放入暂存区
git rm [file1]
#停止追踪文件,但会保留工作区
git rm --cache [file1]
#该名文件,并将这个文件放入暂存区
git mv [origin_name] [new_name]
4.代码提交
shell 复制代码
#提交暂存区到本地仓库
git commit -m "这是第一次提交";
#提交暂存区的 指定文件 到本地仓库
git commit [file1] -m "这是一次指定文件提交" 
#提交自上一次commit的全部变化到本地仓库
git commit -a 

#提交时显示不同diff
git commit -v
#本次的commit代替上一次提交,如果代码没有改变,更改提交信息
git commit --amend -m "这是一个测试堵盖上一次提交的信息" 
#重做上一次commit,包括指定文件的变化
git commit --amend [file1]
5.分支
shell 复制代码
#列出本地分支
git branch
#列出远程分支
git branch -r
#列出所有分支(本地分支和远程分支)
git branch -a
#创建一个分支
git branch [branch_name]
#新建一个分支,并切换到该分支
git checkout -b [branch_name]
#新建一个分支,并指向commit
git branch [branch_name] commit
#新建一个分支,与指定远程分支建立追踪关系
git branch --track [bracnch_name] [remote_branch] 

#切换分支
git checkout [branch_name]
#切换到上一个分支
git checkout -
#现有分支和指定分支建立追踪关系
git branch --set-upstream [branch_name] [remote_branch]

#删除分支
git branch -d [branch_name]
#删除远程分支
git push origin --delete [branch_name]
git branch -dr [branch_name]
#合并指定分支到当前分支
git merge [branch_name]
6.标签
shell 复制代码
#列出所有标签
git tag 
#创建一个标签再当前commit
git tag [tag]
#创建一个标签指定commit
git tag [tag] [commit]

#删除本地tag
git tag -d [tag]
#删除远程tag
git push origin :refs/tags/[tagName] 
#查看tag信息
git show [tag]

#提交指定tag
git push [remote] [tag]
#提交所有tag
git push [remote] --tags
#新建一个分支,并指向指定tag
git checkout -b [branch_name] [tag] 
7.查看信息
shell 复制代码
#显示有变更的文件
git status
#显示当前分支的版本历史
git log 
#显示commit的历史,以及每次的发生变化的文件
git log --stat

#显示暂存区和工作区的差别
git diff
#显示暂存区和上一个commit的差别
git diff -cache [file]
8.远程同步
shell 复制代码
#显示所有远程仓库
git remote -v
#显示指定远程仓库信息
git remote show [remote]
#下载指定仓库
git fetch [remote]

#新增一个远程仓库
git remote add [name] [url]
#拉取远程仓库,并与本地分支合并
git pull [remote] [branch]

#代码推送到远程仓库
git push -u orgin master
#上传 本地指定分支 到 远程仓库
git push [remote] [branch]
#强行推送当前分支到远程仓库
git push [remote] --force
#推送本地所有分支到远程仓库
git push [remote] --all
9.撤销
shell 复制代码
#恢复 暂存区 某个文件到 工作区
git checkout [file]
#恢复 暂存区 所有文件到 工作区
git checkout .
#恢复某个 commit 的指定文件到 暂存区 和 工作区
git checkout [commit] [file]

#重置缓存区 与上次commit一样 但工作区不变
git reset [file]
#重置 工作区和 缓存区
git reset --hard

#重置当前分支 缓存区 为某次 commit,但工作区不变
git reset [commit]
#重置缓存区和工作区为某次commit
git reset --hard [commit]

#暂存与恢复
git stash
git stash pop
相关推荐
Gain_chance12 分钟前
36-学习笔记尚硅谷数仓搭建-DWS层数据装载脚本
大数据·数据仓库·笔记·学习
每日新鲜事1 小时前
热销复盘:招商林屿缦岛203套售罄背后的客户逻辑分析
大数据·人工智能
AI架构全栈开发实战笔记2 小时前
Eureka 在大数据环境中的性能优化技巧
大数据·ai·eureka·性能优化
AI架构全栈开发实战笔记2 小时前
Eureka 对大数据领域服务依赖关系的梳理
大数据·ai·云原生·eureka
Serene_Dream2 小时前
git 合并冲突的分支
git
自挂东南枝�2 小时前
政企舆情大数据服务平台的“全域洞察中枢”
大数据
我是一只puppy3 小时前
使用AI进行代码审查
javascript·人工智能·git·安全·源代码管理
Dragon~Snow3 小时前
Linux Centos9 安装 Elasticsearch
linux·elasticsearch·jenkins
熊延3 小时前
麒麟V10系统安装部署elasticsearch
linux·运维·服务器·elasticsearch·搜索引擎·全文检索
weisian1513 小时前
Elasticsearch-1--什么是ES?
大数据·elasticsearch·搜索引擎