Git命令使用心得
文章目录
- gitignore不起作用
- 回滚到历史某条commit
- 清空历史commit
- 切换分支branch
gitignore不起作用
缓存的问题,删除重新添加即可,在项目根目录下执行
git rm -r --cached .
git add .
git commit -m "update gitignore"
git忽略的基本原理是git设置本地忽略必须保证git的远程仓库分支上没有这个要忽略的文件,如果远程分支上存在这个文件,本地在设置ignore将不起作用,所以需要执行
git rm -r --cached .idea
回滚到历史某条commit
git log
git reset –hard commit_hash
git push origin HEAD –force
以上会回滚到以前某一个commit中,参考链接
Github Git彻底删除历史提交记录的方法
清空历史commit
主要作用是删除提交记录中的敏感信息,处理步骤:
git checkout --orphan latest_branch
git add -A
git commit -am "commit message"
git branch -D master
git branch -m master
git push -f origin master
以上,经本人测试,完全可达到要求,参考链接
- git仓库删除所有提交历史记录,成为一个干净的新仓库
- how to delete all commit history in github? [duplicate]
切换分支branch
Intelj界面化方法就是git --> Repository --> Pull
在弹出到对话框中选中你想要到分支即可
Intellij Idea git切换远程分支