ssh
ssh-keygen -t rsa -C 'youremail@qq.com'
再到路径下复制公钥到git配置中
分支
git branch 查看分支
git checkout -b new_branch 新建分支new_branch
git checkout branch2 切换到另一个分支branch2
git branch -D local_branch 删除分支local_branch
git push origin --delete remote_branch 删除远程分支remote_branch
提交
git add file1 file 提交到暂存区
git commit file1 file2 -m 'comment' 提交到仓库区
git commit -a 提交上一次commit之后的所有变化
git push origin local_branch:remote_branch 提交到远程分支remote_branch
拉取
git fetch 下载远程仓库的所有变动(还没合)
git merge origin/remote_branch 合并远程分支remote_branch到本地分支中
git pull origin remote_branch:local_branch 等于fetch+merge
解决冲突
merge后提示冲突,此时需要手动解决
git status 查看有冲突的文件
冲突文件中会出现这样的字段
<<<<<<<HEAD
remote data blablabla
=======
local data blablabla
>>>>>>> local_branch
保留自己想要留的内容,把其他行删掉
再add commit push即可
查看log
git status 显示所有有变更的文件
git diff 显示暂存区和工作区的区别
git diff branch1 branch2 显示两个分支的差别
git log 现实当前分支的版本历史
git log --stat 显示commit历史,以及每次commit发生变更的文件
git show [commit] 显示某次commit的内容变化
git blame file 查看文件的变更记录
撤销
git checkout file 恢复暂存区的指定文件到工作区(还未add)
git reset file 重置暂存区的文件file到上一次commit,但工作区不变(还未commit)
git reset --hard 重置暂存区和工作区与上一次commit一致(还未commit)
git reset --hard [commit] 重置暂存区和工作区与某一次commit一致