查看 git 配置信息
1 | $ git config --list |
全局设置
1
2git config --global user.name "{{userName}}"
git config --global user.email "{{userEmail}}"修改当前项目的 git 配置信息
1
2
3
4
5
6
7
8
9
10
11ls -a
cd .git/
vi config
add
[user]
name = {{userName}}
email = {{userEmail}}
or
git config user.name "{{userName}}"
git config user.email "{{userEmail}}"
查看分支
1 | git branch 查看本地分支 |
创建一个新分支
1 | git checkout -b {{branch}} |
切换分支
1 | git checkout {{branch}} |
删除分支
1 | git branch -D {{loaclBranch}} |
合并分支
1 | $ git merge {{branch}} 将 branch 与当前分支合并 |
储藏修改
1 | git stash 当你想切换到其他分支又不想提交现在修改的东西时,当你在修改好前想 git pull 时,用 git stash 来得到一个干净的工作目录 |
查看提交历史
1 | git log |
查看 commit head message
1 | git reflog |
打 tag
1 | git tag {{tagName}} |
删除 tag
1 | git tag -d {{localTag}} |
给一个历史提交添加 tag
1 | // Set the HEAD to the old commit that we want to tag |
push 后发现没加 .gitignore,删除本地及远程的冗余提交
1 | git rm -r --cached . |
修改已经 commit 的邮箱和用户名
1 | // get the commit we want to modify |
修改已经 push 的 commit 的邮箱和用户名
1 | // clone a new repo |
1 | // copy the script below and modify the variables: OLD_EMAIL, CORRECT_NAME, CORRECT_EMAIL |
1 | // then press enter to run the script |
修改已经 push 的 commit message
1 | 方法一: |
修改已经 push 的提交内容
1 | git reset --hard {{commitId}} |
解决提交前的 conflict,协同工作必备
1 | // 先不提交修改的内容直接创建新分支 temp ,若已 commit 则创建新分支后在本分支 reset 到上一个 commit ,再执行 git pull |
git 删除远程仓库的某次错误提交
1 | git reset --hard HEAD~1 |
- 需注意,其实这种方法仅适用于删除最新的一次提交,如果某次错误提交后又有了一个新的提交,则强制删除错误提交会导致后面的提交也消失,因此需慎用此方法,尤其是在多人协作项目上(°ー°〃)
gerrit merge 前执行 git commit –amend 改写上次提交,并将 gerrit 上的 changeid 加入到上次提交的 commit message 下面(上下各空一行),再 git push(还是原来的 commit,不产生新的提交)
bash ctrl+R 快速查看输入过的命令
git 创建仓库并关联到 github
- cd 到项目目录,git init 初始化,使 git 对此项目进行版本控制
- git add .
- git commit -m ‘’
- 在 github 上创建一个新仓库 create a new repository
将本地项目关联到建立的新仓库上
remote add origin {{url}}``` 1
2* 运行 ```$ git remote -v``` 查看 origin 关联
* ```git push -u origin master若本地已有代码非空, 则直接
remote add origin {{url}}``` 1
* ```git push -u origin master
若将一个 git 仓库关联为另一个 git 仓库,则
ls -a
删除 .git/ 文件夹即可
删除 git 版本控制, 然后再执行 remote