查看差异
git diff HEAD -- CMakeLists.txt
git diff HEAD
解决冲突
参考:https://blog.csdn.net/misakaqunianxiatian/article/details/51103734
git pull的时候提示"Please, commit your changes or stash them before you can merge. error: The following untracked working tree files would be overwritten by merge: xxx. Please move or remove them before you can merge."
git stash // 将目前对代码的修改stash起来
git pull // pull最新代码
git stash pop // 执行完这句之后,自己的修改会被pop出来,这时候可能和上一句pull下来的代码有冲突,有冲突则自己解决冲突(即在每个有merge冲突的地方选择保留自己的修改还是pull下来的代码),解决完冲突之后add,然后commit
git add
git commit -m "solve conflict"
git pull
git push
撤销add
如果多add了文件,则git rm掉这些文件
git rm 1.txt
git commit -m "remove xxx"
git push
撤销commit
git add
git commit
这时候发现commit信息写错了或者不想commit,则采用以下方案:
git reset --soft HEAD^ // 成功撤销commit,写的代码仍然保留
增加gitignore
vim .gitignore
在.gitignore文件里面添加需要忽略的文件
回退到某个版本
git reset --hard 2d27f84d
git reflog得到操作的所有版本id信息
在某个文件夹xx下git init,则文件夹xx成为被git管理的文件夹
clone代码
git clone xxx -b master // xxx是从仓库的地址
查看分支
git branch
git cherry pick
参考:git cherry-pick 教程