Git常见命令&&流程
个人自用
- git clone 仓库
- git checkout -b my-feature
- 切换到需要修改的分支
- 修改代码
- git diff
- 查看当前修改后的代码与原来my-feature中的代码有哪些区别
- git add xxx
- 将代码添加到暂存区
- git commit -m “xxx”
- [Feature]: New module or features.
- [Bugfix]: Fix something.
- [Refactor]: Style check.
- git push origin my-feature
- 将本地my-feature分支推送到remote的my-feature分支,如果没有则自动创建
- push完成后,准备合并branch到main中(这个过程是pull request, PR)
- squash and merge
- 删除remote(主仓库)中的my-feature
- git branch -D my-feature(一般不删除)
- 删除local branch
- git pull origin master
- 拉去主仓库中的最新更新
- 结束
- 如果remote main代码有更新
- git checkout main
- git pull origin master
- 把远端的main同步到local的main中
- git checkout my-feature
- git rebase main
- 把my-feature暂时丢弃,将最新的main进行更新,然后再把添加my-feature的修改
- 有可能出现rebase conflict,手动选择你想要的代码
- 然后git rebase --continue
- 进行完rebase后,git push -f origin my-feature
- 由于进行了rebase,需要加上-f,表示force,强行push
创建自己的新仓库然后更新代码
- 首先安装git,添加ssh,配置git信息
- 使用
- git remote add origin https://github.com/repo_name/proj_name.git 来关联远程仓库
- 如果之前关联过的
- git remote set-url origin https://github.com/repo_name/proj_name.git
- 使用上面的重新关联
- push代码可能会出现无权限错误,用下面的token法解决https://blog.csdn.net/yjw123456/article/details/119696726
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Hongwen Xin's Blog!