http://www.cheat-sheets.org/saved-copy/git-cheat-sheet.pdf
- git branch 查看本地所有分支
- git status 查看当前状态
- git commit 提交
- git branch -a 查看所有的分支
- git branch -r 查看远程所有分支
- git add files 把文件的修改添加到暂存区
- git commit 把暂存区的修改提交到当前分支,提交之后暂存区就被清空了
- git reset --files 使用当前分支上的修改覆盖暂缓区,用来撤销最后一次 git add files
- git checkout --files 使用暂存区的修改覆盖工作目录,用来撤销本地修改
- git commit -a 直接把所有文件的修改添加到暂缓区然后执行提交
- git checkout HEAD --files 取出最后一次修改,可以用来进行回滚操作
- git merge --no-ff -m "merge with no-ff" dev
快进式合并(fast-farward merge):会直接将 master 分支指向合并的分支,这种模式下进行分支合并会丢失分支信息,也就不能在分支历史上看出分支信息。
解决方法:可以在合并时加上 --no-ff 参数来禁用 Fast forward 模式,并且加上 -m 参数让合并时产生一个新的 commit。 - git stash 将当前分支的修改储藏起来
- git cherry-pick
git cherry-pick <commit id>:单独合并一个提交
git cherry-pick -x <commit id>:同上,不同点:保留原提交者信息。
git cherry-pick <start-commit-id>..<end-commit-id>
git cherry-pick <start-commit-id>^..<end-commit-id>
1. git切换远程链接
git remote set-url origin xxxxxxxx
2. 回退到某次提交版本
# 回退命令:
$ git reset --hard HEAD^ 回退到上个版本
$ git reset --hard HEAD~3 回退到前3次提交之前,以此类推,回退到n次提交之前
$ git reset --hard commit_id 退到/进到 指定commit的sha码
# 强推到远程:
$ git push origin HEAD --force
3. 修改分支名称
# 切换分支
git checkout <branch>
# 重命名本地分支
git branch -m <new_branch_name>
# 重命名旧分支名为新分支名称(ps:git push origin :"old_test" "new_test")
git push <remote> :<old_branch_name> <new_branch_name>
# 为新创建的分支设置upstream分支(ps:git push origin -u new_test)
git push <remote> -u <new_branch_name>