标签: gitgit
查看 git 配置信息github
$ git config --list or $ git config -l
设置 git 配置信息shell
全局设置bash
$ git config --global user.name "{{userName}}" $ git config --global user.email "{{userEmail}}"
修改当前项目的 git 配置信息 <!--more-->url
$ ls -a $ cd .git/ $ vi config add [user] name = {{userName}} email = {{userEmail}} or $ git config user.name "{{userName}}" $ git config user.email "{{userEmail}}"
查看分支版本控制
$ git branch 查看本地分支 $ git branch -r 查看远程分支 $ git branch -a 查看全部分支
建立一个新分支code
$ git checkout -b {{branch}}
切换远程分支orm
$ git checkout -b {{branch}} origin/{{branch}}
删除分支ip
$ git branch -D {{loaclBranch}} $ git push --delete origin {{remoteBranch}}
合并分支rem
$ git merge {{branch}} 将 branch 与当前分支合并
查看 commit head message
$ git reflog
打 tag
$ git tag {{tagName}} $ git push origin {{tagName}} or $ git push --tags
删除 tag
$ git tag -d {{localTag}} $ git tag -d {{remoteTag}} $ git push origin :refs/tags/{{remoteTag}}
给一个历史提交添加 tag
// Set the HEAD to the old commit that we want to tag $ git checkout {{leading 7 chars of commit}} // temporarily set the date to the date of the HEAD commit, and add the tag $ GIT_COMMITTER_DATE="$(git show --format=%aD | head -1)" git tag -a {{tag}} -m "{{commit message}}" // set HEAD back to whatever you want it to be $ git checkout master $ git push --tags
push 后发现没加 .gitignore,删除本地及远程的冗余提交
$ git rm -r --cached . $ git add . $ git commit -m "{{commit message}}"
修改已经 commit 的邮箱和用户名
// get the commit we want to modify $ git log // go to the commit $ git reset --soft {{commitId}} $ git commit --amend --author='{{userName}}<{{userEmail}}>' $ git push
修改已经 push 的 commit 的邮箱和用户名
// clone a new repo git clone --bare https://github.com/user/repo.git cd repo.git
// copy the script below and modify the variables: OLD_EMAIL, CORRECT_NAME, CORRECT_EMAIL #! /bin/sh git filter-branch --env-filter ' OLD_EMAIL="" CORRECT_NAME="Your Correct Name" CORRECT_EMAIL="your-correct-email@example.com" if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ] then export GIT_COMMITTER_NAME="$CORRECT_NAME" export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL" fi if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ] then export GIT_AUTHOR_NAME="$CORRECT_NAME" export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL" fi ' --tag-name-filter cat -- --branches --tags
// then press enter to run the script // checkout if there any error in new git and push $ git push --force --tags origin 'refs/heads/*' // delete the temporary clone $ cd .. $ rm -rf repo.git
修改已经 push 的 commit message
方法一: $ git commit --amend $ git push --force 方法二: $ git rebase -i HEAD~n change the `pick` to `reword`, which means edit the commit message save and exit and then update the commit message as you like and :wq $ git push --f
修改已经 push 的提交内容
git reset --hard <commit_id> git add . git commit --amend git push origin HEAD --force
解决提交前的 conflict,协同工做必备
// 先不提交修改的内容直接建立新分支 temp ,若已 commit 则建立新分支后在本分支 reset 到上一个 commit ,再执行 git pull $ git checkout -b temp $ git add . $ git commit -m 'commit message' // 此时的master 分支是干净的,无本身的提交 $ git checkout master // 拉取远程修改 $ git pull // 复制刚刚提交的 commit-id commit-a, 将本身的提交 cherry-pick 进去 $ git cherry-pick commit-a // 若是有冲突 fix it $ git add . $ git cherry-pick --continue // then push $ git push
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
将本地项目关联到 github 上 git remote add origin {{url}}
git push -u origin master
Github Pages 发布静态页面
repository-Settings-Github Pages-select a source and save