git的使用详解

2023-04-06编程技术191349

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

本文地址:https://www.ufcn.cn/tutorials/2397336.html

如非特殊说明,本站内容均来自于网友自主分享,概不代表本站观点,如有任何问题我们都将在收到反馈后的第一时间进行处理!