Git 命令操作
常用命令
git add .
git commit -m '内容描述【publish new demand】'
git pull/push
git log -p / --stat
git checkout -p fileName
1. Init/config
git init
git config --list
git config --global user.name "User Name" user.email xxx@xxx.com
git fetch origin --prune
2. Remote
git remote -v
git remote show remoteName
git fetch remoteName
git clone git:
git remote add remoteName https:
git remote rename remoteName newRemoteName
git remote rm remoteName
3. Tag
git tag / git tag -l
git tag -a tagName -m "注释"
git push origin tagName
git tag -d tagName
git push remoteName tagName
git ls-remote --tags remoteName
git fetch remoteName tagName
4. Stash
git stash
git stash save "备注的内容"
git stash list
git stash clear
git stash apply
git stash pop
git stash drop
5. Branch
git branch -v
git branch -a
git checkout --orphan newBranchName
git branch brachName
git branch -D brachName
git push origin --delete brachName
git push origin brachName
git checkout brachName
git merge brachName / git merge brachName --squash
git checkout -b brachName origin/brachName
git branch -m oldBranchName newBranchName
git push origin oldBranchName
git branch -u origin/brachName / git branch --set-upstream-to origin/brachName
git branch --unset-upstream
6. Log/diff/checkout
// 列出最近的2条commit记录
git log -2 --pretty=format:"%h %s %an %cd" --date=format:%Y-%m-%d\ %H:%M
-2 最近 2 条
%h 哈希值/commitid
%an 作者名字
%cd 提交日期
%s 提交说明
// 列出提交记录 显示文件列表
git log --stat --pretty=format:"%h %s %an %cd" --date=format:%Y-%m-%d\ %H:%M
// 列出某段时间的提交记录
git log --before="2021-09-10" --after="2021-09-08"
// 列出某个文件的记录
git log -p src/page/onduty/components/month.vue
// 列出出分支1、分支2 所有有差异的文件列表
git diff branch1 branch2 --stat
// 列出指定文件的详细差异
git diff branch1 branch2 filePath
// 列出本地分支 远程分支差异
git diff branch remoteName/branch
// 查看文件在某处commitId的提交改动
git show commitId filePath
// 未add前,撤消 filePath 所做的修改
git checkout filePath
git checkout --patch B_branch f.txt || git checkout -p B_branch f.txt
// 合并单个文件,将远程remoteName/branch分支的filePath合并到本地
git checkout -p remoteName/branch filePath
合并某个 commitId 到当前分支
git cherry-pick commitId
7. 修改提交的注释信息
// 未 push 修改commit的提交commit msg
git commit
// 已经push
1、git rebase -i HEAD~3
2、进入输入模式 将pick 改为 edit, wq! 保存退出
3、git commit
4、git rebase
5、git push -f remoteName branchName
8. 回滚
git checkout .
git checkout <fileName>
git checkout commit_log_id
git reset HEAD .
git reset HEAD a.txt
git reset --hard HEAD
git reset --hard <commit_log_id>
git revert <commit_log_id>
git revert // 是用一次新的commit来回滚之前的commit,此次提交之前的commit都会被保留;
git reset是回到某次提交