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