git工作流,持续踩坑
因为我同时使用两个操作昔日,因此github仓库就产生一个同步的问题。但是只会 add commit push
三步,因此学习一下
工作区:本地文件。git clone 下载到工作区,git pull 更新到工作区
暂存区:add 提交到暂存区。
本地仓库: commit 提交到本地仓库。fetch 从远程更新到本地仓库
远程仓库:push 提交到远程仓库。
工作流
- git clone 后切换分支
1 2 3
| git clone <remote> git checkout -b feature/windows git branch -a
|
- 写点东西提交
1 2 3 4
| git diff git add xxx git commit
|
- push 到仓库
1 2 3 4 5 6 7 8 9 10
| git checkout main git fetch origin git diff git pull origin main git checkout feature/windows
git rebase main git push -f origin feature/windows
|
- main 远程分支合并
- 在 github 类似的地方提交一个
pr(pull request)
,将 feature/windows
合并到 main
分支里
- 经过项目开发者审查,会进行合并。
- 删除远端
feature/windows
- 删除本地分支
1 2 3 4
| git checkout main git branch -D feature/windows
git pull origin main
|
因此创建三个分支来维护。
子模块
- 将子模块文件夹加入到
.gitignore
文件内容中,这样主项目就能够无视子项目的存在。
- git submodule 使用
1 2 3 4
| git submodule add https://github.com/chaconinc/DbConnector
git submodule update --remote <repo>
|
版本回退
最新的不一定是最好的,还可能是bug 多多的
1 2 3 4 5 6 7 8 9 10 11
| git branch -a
git checkout <branch> <tag>
git checkout <branch>
git log git checkout <comit_hash>
|
删除
1 2 3
| git remote rm -r --cached <dir/filename> git commit -m "delete" git push origin main
|
但是现在比较好的IDE只需要点击一下鼠标就行,也是很方便。