Last active
May 9, 2017 06:10
-
-
Save xgz123/9b70e564c14ca68f054fd62b837d1336 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1, 重写历史 | |
# https://git-scm.com/book/zh/v1/Git-%E5%B7%A5%E5%85%B7-%E9%87%8D%E5%86%99%E5%8E%86%E5%8F%B2 | |
git commit --amend # 修改最近一次提交 | |
git rebase -i HEAD~3 # 交互式修改最近三次提交, 通过命令p(使用)/s(压制)/e(修改)做修改,删除,合并commit等操作 | |
git rebase -i --root # 如果只有两次提交 | |
git reset --hard HEAD~3 # 撤销最近三次提交,文件也恢复, 这三次丢失 | |
# 找回历史 | |
git reflog | |
git reset --hard <head> # 这样就能找回来了 | |
git push --force origin feature-branch # 强制提交到远程 | |
git filter-branch --tree-filter 'rm -f passwords.txt' HEAD --all #在所有分支的每个commit里删除这个文件 | |
git rebase --abort # 撤销修改 | |
# 2. 创建远程分支并推送 | |
git checkout -b localbranch # 创建新分支 | |
git push origin localbranch:remotebranch # | |
# 3. 将远程分支影射映射到本地 | |
git fetch # 获取信息 | |
git checkout -b localbranch origin/remotebranch | |
git clone -b branchname [remote address] # 拉取远程的一个分支 | |
git clone --depth <depth> -b <branch> <repo_url> # 丢弃历史 | |
# 4. 修改branch名称 | |
# master一般被拒绝删除,是因为设置了主分支 | |
git branch -m oldname newname | |
git push origin :old_branch # Delete the old branch | |
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote | |
# 5. 列出文件 | |
git ls-files | |
# 6. log - alias | |
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)\<%an\>%Creset' --abbrev-commit" | |
git config alias.st "status" | |
git config alias.cm "commit -m" | |
# 7. diff | |
git diff upstream/dev |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment