git代码管理及提交

背景

学习git代码的管理及提交

  1. git clone 【克隆代码到本地】
  2. git checkout -b $localbranch 【创建本地分支】
  3. git push origin $localbranch:$localbranch 【将创建好的分支提交到远程代码仓库】
  4. git branch -D $localbranch 【强制删除本地分支】 
  5. git push origin --delete [branch_name] 【删除远程分支】
  6. git branch -a  【查看全部的分支】
  7. git branch 【查看本地当前的分支等信息】
  8. git status 【查看当前本地的状态】
  9. git checkout 分支名 【本地切换分支】
  10. git add 修改的文件 【把修改的文件放入到本地】
  11. git commit -m "提交信息" 【本地分支提交】
  12. git push origin HEAD:refs/for/远程分支名 【本地分支提交到远程分支】
    1. /refs/for 的意义在于我们提交代码到服务器之后是需要经过code review 之后才能进行merge的,而refs/heads 不需要
    2. HEAD执行本地当前的分支
  13. git reset -hard $commit_id 【版本回退到指定的版本】
  14. git revert -n $commit_id 【版本撤销给的commit_id的版本】
  15. git diff $file_name 【比较工作区与暂存区的diff】
  16. git commit --amend 【修正commit提交的内容】
    1.  如修正邮箱,git commit --amend --author="username <username@email.com>"
  17. git config --global设置用户名和邮件 【这是因为git分布式版本控制系统,让机器自报家门】
    1. git config --global user.name "xxx"
    2. git config --global user.email "xxx@zzz.com"
  18. git rebase master 【解决代码冲突, 在dev分支上进行】
    1. 修改代码冲突的地方
    2. git add $change_file
    3. git rebase --continue
    4. git push origin HEAD:refs/for/master
  19. git remote -v # 查看远程仓库地址信息
  20. git pull origin test_hight_trip_hight_sway_about_2_group # 拉取指定的分支
  21. git checkout . 清除修改的文件,前提文件没有add; 参考:https://blog.csdn.net/weixin_34178244/article/details/91367518
  22. git branch --set-upstream-to=origin/test test # 将本地的分支与远程的分支进行关联
  23. git stash 【暂存自己的代码,随意切换分支,返回后依然能够恢复代码】https://www.cnblogs.com/mzy520/p/11282751.html
  24. git checkout -b $local_branch origin/$local_branch  # 拉取远程分支到本地对应分支
  25. git remote set-url origin https://gitlab.ctbiyi.com/hyperserver/gpu-manager.git #换远程代码库
  26. git rebase -i $commit_id  # 合并提交过的分支,$commit_id为要合并之前的提交
    1. 修改成,squash: 保留这个commit,但是会将这个commit融入上一个commit
    2. 保存退出
    3. git commit --amend # 修改提交的message
    4. git push -f # 强制推送到远程
  27. git rebase --abort # 取消git rebasing

参考

  1. https://www.cnblogs.com/yaozhongxiao/p/3794963.html
  2. https://www.cnblogs.com/qianqiannian/p/6008140.html
  3. https://blog.csdn.net/yxlshk/article/details/79944535
  4. https://blog.csdn.net/ezhchai/article/details/79387452
  5. https://www.jianshu.com/p/7def4f387e9f
  6. https://www.cnblogs.com/mzy520/p/11282751.html
  7. https://blog.csdn.net/u011077027/article/details/101023749
posted @ 2020-05-13 16:10  威威后花园  阅读(285)  评论(0编辑  收藏  举报