Git常用命令 (持续更新)

生成SSH Key:

ssh-keygen -t rsa -C "<email>"

设置:

git config --global user.email "<email>"
git config --global user.name "<name>"

添加remote:

git remote add <name> <path>
git pull <name> <branch> --rebase

使用pull <name> <branch> –rebase冲突后, 修改好冲突后 merge:

git add .
git pull --continue

查看改动:

# 查看还没有暂存起来的变化内容
git diff
# 查看已经暂存起来的文件(staged)和上次提交时的的差异
git diff --cached
git diff --staged
# 显示工作版本(working tree)和HAD的不同
git diff HEAD
# 当前目录与另一个分支的差别
git diff <branch>
# 比较上次提交和上上次提交
git diff HEAD^ HEAD

取消改动:

# 放弃当前未暂存的改动
git checkout .
# 放弃git add .暂存后改动
git reset HEAD
# 放弃commit后但未push的改动,需要重新修改再push
git reset <commit_id>
# 放弃push到git后的改动
git reset --hard <commit_id>
git push origin HEAD --force

覆盖上一条已经提交的commit:

git add .
git commit --amend
git push origin <branch> -f

删除远程ignored的文件:

git rm -r --cached .
git add .
git commit -m "Removing all files in .gitignore"

拉取远程分支并提交:

git checkout -b <branch> <remote>/<branch>
git push --set-upstream origin <branch>

查看分支跟踪情况/设置新的跟踪

git branch -vv
git branch --set-upstream <branch> <remote>/<branch>

    原文作者:git
    原文地址: https://segmentfault.com/a/1190000010609800
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞