Git常用命令

git常用命令集合
显示command的help

1
2
3
4
5
git 
help
<
command
>

显示某次提交的内容 git show $id

1
2
git 
show

将工作文件修改提交到本地暂存区

1
2
3
4
5
git 
add
<
file
>

查看该文件每次提交记录

1
2
3
4
5
6
7
git 
log
 git 
log
 <
file
>

查看最近两次详细修改内容的diff

1
2
3
git 
log
 --

列所有stash

1
git stash list

抓取远程仓库所有分支更新并合并到本地

1
git pull

将本地主分支推到远程主分支

1
2
3
4
git 
push
origin
 master

将本地主分支推到远程(如无远程主分支则创建,用于初始化远程仓库)

1
2
3
4
5
git 
push
 -u 
origin
 master

查看远程服务器地址和仓库名称

1
git remote -v

查看远程服务器仓库状态

1
2
3
git remote 
show
origin

待续……

①Github新增仓库并clone至本地修改文件

  1. 将文件添加至暂存区:
1
2
3
git 
add
.
  1. 提交至本地仓库
1
2
3
git
commit -m
'commit'
  1. 推送至远程仓库
1
2
3
4
5
6
7
8
9
10
11
git push origin 
master
# 正常提交
git
push -u origin
master
/main 
# 首次提交
git push --force origin
master
# 覆盖提交,本地覆盖远程

②本地仓库连接远程仓库

  1. git init初始化本地仓库,并修改仓库文件
1
2
git 
init
  1. 添加至暂存—>本地仓库
1
2
3
4
5
6
7
git 
add
.
git
commit
-m 
'commit'
  1. 如果当前用户目录下没有.ssh目录,就创建。创建后需要输入Github密码,然后一直回车
1
2
3
4
ssh-keygen -
t
 rsa -C 
"xxx@xxx.com"
  1. Github—>Setting—>SSH and GPG keys—>New SSH key,Title随便填、Key值为id_rsa.pub的值
  2. 创建Github仓库(无需创建README文件),本地仓库执行连接远程仓库
1
2
3
4
5
git remote add origin https:
//gi
thub.com
/username/
rep.git
  1. 将本地仓库内容推送至Github
1
2
3
4
5
git 
push
 -u 
origin
 master
  1. 上传超过100MB的大文件

下载lfs后安装在电脑中,然后在git中导入文件

git git lfs migrate import --include="*xxx.mp4"

Git常用命令
https://zhouyinglin.top/2023/03/02/Git常用命令/
作者
小周
发布于
2023年3月2日
许可协议