git命令汇总(持续更新)
1. 展示当前分支:
git branch --show-current
2. 代码提交到本地仓库:
git commit -m "XXXX"
3. 代码推送到远程仓库:
git push origin branch-name
4. 切换分支(合并分支前,需要切换到目标分支):
git checkout branch-name_to
5. 合并源分支代码到目标分支:
git merge branch-name_from
6. 合并后推送到远程仓库:
git pull
git push origin branch-name_to
7. 保存当前修改:
git stash
8. 将保存的修改应用到新分支上:
git checkout branch-name_new
git stash list
git stash apply
合并代码时遇到"please enter a commit message to explain why this merge is necessary":
1) 按“i”键进入插入模式
2)修改黄色部分为自定义的合并原因(如果不想改就跳过此步)
3)按“ESC”退出插入模式
4)最底下一行输入“:wq” 等待合并完成