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
相关推荐
FksLiao30 分钟前
Superset配置Report & Alert实践及二次开发实践
大数据·superset
PowerBI学谦5 小时前
Python in Excel高级分析:一键RFM分析
大数据·人工智能·pandas
WHYBIGDATA7 小时前
Hive之分区表
大数据·hive·hadoop
梦醒沉醉9 小时前
HBase Shell
大数据·数据库·hbase
caihuayuan510 小时前
MySQL:MySQL8.0 JSON类型使用整理,基于用户画像的案例
java·大数据·spring boot·后端
disgare12 小时前
Hadoop 基础原理
大数据·hadoop·分布式
阿里云大数据AI技术12 小时前
阿里云 MaxCompute MaxQA 开启公测,解锁近实时高效查询体验
大数据·阿里云·云原生·实时数仓·maxcompute
moton201713 小时前
二.数据治理流程架构
大数据·数据安全·etl·数据管理·数据架构·数据流程·数据生命周期
饮长安千年月14 小时前
IOT-CVE-2018-17066(D-Link命令注入漏洞)
大数据·网络·物联网·安全·elasticsearch·搜索引擎
leeindex14 小时前
ES 渗透查询 (Percolate query)
大数据·elasticsearch·搜索引擎·全文检索·中文分词·渗透·lucene