一些git常用指令和自己使用时遇到的坑。
使用git config --
先cd
路径,然后使用git init
注意:进到要提交的文件夹里,不要在父文件夹就使用git
git status
git add .
git commit -m "message"
git log --oneline
※log有航海日志的意思,很形象!
※oneline的作用是返回一行描述
※退出按q
git checkout <commit><file>
eg. git checkout afdbf46 (就是那个开头有颜色的六位数哈~)
git reset HEAD <index.html>
坑:注意checkout的时候已经把文件拉下来了,要使用reset需要用checkout拉下最后一次提交的文件。
坑:Git HEAD detached from XXX ,游离状态后的提交无法追溯。
git 指针游离的解决方案
两个服务商:github和bitbucket
这里说下bitbucket
在大陆比较低调的服务商,优势是私人仓库不像github一样抠搜。
git remote add origin <URL>
git push -u origin master
※注意如果是推到github仓库里,主干名字可能是main而不是master
※大坑:如果建了远程仓库,这个仓库和本地仓库是独立的,需要用pull连接起来,而且,得allow合并
解决关键:git pull origin master --allow-unrelated-histories
参考资料
※大坑:Git 提示fatal: remote origin already exists
如果已经存在远程仓库了,需要手动删除
git remote rm origin
参考资料
#1 git新手常用指令和一些坑 (bootstrap4系列)
原文:https://www.cnblogs.com/rosecanoe/p/15142819.html