温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

git的使用详解

发布时间:2020-08-06 11:43:14 来源:网络 阅读:451 作者:PlayWithYou 栏目:开发技术

1.git分支操作常用命令

    查看分支:git branch

    创建分支:git branch name

    切换分支:git checkout name

    创建+切换分支:git checkout -b name

    合并某分支到当前分支:git merge name

    删除分支:git branch -d name

    删除远程分支:git push origin :name

    撤销修改:git checkout filename

    删除文件:git rm file

    重命名文件:git mv oldname newname

    查看状态:git status

    添加记录:git add file 或 git add .

    添加描述:git commit -m "miao shu nei rong"

    修改描述:git commit --amend

    同步数据:git pull

    提交数据:git push origin name

    代码回滚:git reset --hard commit-id (--hard清除本地的所以修改,不加不会清除本地的修改)


2.git生成patch和打入patch


2.1 使用git format-patch生成所需要的patch:
    当前分支所有超前master的提交:
    

     git format-patch -M master


    某次提交以后的所有patch:
   

     git format-patch 4e16... --4e16指的是commit名

    从根到指定提交的所有patch:
    

     git format-patch --root 4e16


    某两次提交之间的所有patch:

     git format-patch 365a..4e16 --365a和4e16分别对应两次提交的名称


    某次提交(含)之前的几次提交:

     git format-patch –n 07fe --n指patch数,07fe对应提交的名称

    故,单次提交即为:

     git format-patch -1 07fe


git format-patch生成的补丁文件默认从1开始顺序编号,并使用对应提交信息中的第一行作为文件名。如果使用了-- numbered-files选项,则文件名只有编号,不包含提交信息;如果指定了--stdout选项,可指定输出位置,如当所有patch输出到一个 文件;可指定-o <dir>指定patch的存放目录

2.2 patch的应用   

    先检查patch文件:git apply --stat newpatch.patch
    检查能否应用成功:git apply --check newpatch.patch
    打补丁:git am --signoff < newpatch.patch

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI