Git指令

本文最后更新于 2024年9月22日 晚上

1
2
git config --global user.name ""
git config --global user.email
1
2
3
git init
git add *.c
git commit -m "message"
1
git clone https://github.com/libgit2/libgit2 mylibgit
1
git status
1
git diff
1
2
3
4
5
6
7
git log -p -2
# -p代表显示每次提交的内容差异,-2表示仅显示最近两次的提交
git log -stat
#统计数据
git log --pretty=oneline
git log --pretty=format:"%h - %an, %ar : %s"
git log --since =2.weeks
1
2
git commit -amend
#撤销
1
git reset HEAD CONTRIBUTING.md
1
git checkout -- CONTRIBUTING.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
git remote -v
#查看远程仓库
git remote add pb https://...
# pb是简写
git fetch [remote-name]

git push origin master

git show

git remote rename pb paul
# 重命名
git remote rm paul
# 删除
1
2
3
git tag
# 列出标签
git tag v1.4 -m "my version 1.4"
1
2
3
4
5
6
7
8
git checkout -b iss53
#创建并切换到分支
git branch -d hotfix
#删除
git branch --merged
git branch --no-merged
git merge A.txt
#合并
1
git push origin serverfix
1
2
3
4
5
6
7
8
9
git fetch origin
#从服务器上抓取数据
git checkout --track origin/serverfix
git checkout -b sf origin/serverfix
# 拉取分支,sf是自定义名
git branch -vv
#查看追踪分支
git branch -u orgin.serverfix
# 设置已有的本地分支跟踪一个刚刚拉取下来的远程分支
1
2
3
4
git fetch
# 从服务器上抓取本地没有的数据
git pull
# 含义是git fetch + git merge
1
2
git push origin --delete serverfix
# 删除远程分支
1
2
git rebase master
# 将当前分支变基到master分支上
image-20240919142734429
1
2
git checkout feature
git rebase master
image-20240919142743629
1
2
3
4
git clone /opt/git/project.git
git clone file:///opt/git/project.git
git remote add local_proj /opt/git/project.git
# 增加本地版本库到现有的Git项目
1
2
scp -r test.git meteor041@github.com:meteor041/test.git

1
2
3
4
5
cd ~./ssh
ls
# 查看密钥
ssh-keygen
# chuang'jian

Git指令
https://meteor041.git.io/2024/09/22/Git指令/
作者
meteor041
发布于
2024年9月22日
许可协议