Git常用(持续更新)

常用场景:

初始化:

git config --global user.name "codelabs"
git config --global user.email my@codelabs.com
git init
git remote add origin https://github.com/username/repository.git
git pull origin master

提交:

git add ./git add <file1> <file2> ...
git commit -m "Your commit message here"
git push

撤回:

参考最后的链接。

Patch:

  1. 找到要生成 patch 的提交范围:确定要生成 patch 的提交范围,可以是单个提交、一系列连续的提交,或者两个提交之间的差异。

  2. 使用 git format-patch 生成 patch:在命令行中执行以下命令:

    git format-patch <commit> --stdout > my_patch.patch
    

    其中 <commit> 是要生成 patch 的提交范围的最后一个提交。这将生成一个名为 my_patch.patch 的文件,其中包含了从指定提交到当前 HEAD 的所有更改。

  3. 传输 patch 文件:将生成的 patch 文件传输给其他人或应用程序。您可以使用电子邮件、文件共享服务等方式发送文件。

  4. 应用 patch :其他人或应用程序可以使用 git apply 命令将 patch 应用到其本地代码库中。例如:

    git apply my_patch.patch
    

合并:

git checkout main
git merge feature
git add <conflicted_file>
git commit
git commit -m "Merge feature branch"

Git rebase和Git merge区别,然后rebase会丢失提交,所以一般用merge。

只合并一个或者几个提交的话,可以用cherrypick

git cherrypick <commit-hash-1> <commit-hash-2> ...

最后很推荐的是这个网站,玩游戏方式学习git

Learn Git Branching

参考:

Git 的 4 个阶段的撤销更改

45 个 Git 经典操作场景,助你一臂之力

动图展示 10 大 Git 命令,一目了然

C++ 实践 | Git 入门

相关推荐
int WINGsssss2 小时前
Git使用
git
用户0760530354384 小时前
Git Revert:安全移除错误提交的方式
git
Good_Starry16 小时前
Git介绍--github/gitee/gitlab使用
git·gitee·gitlab·github
云端奇趣21 小时前
探索 3 个有趣的 GitHub 学习资源库
经验分享·git·学习·github
F_D_Z1 天前
【解决办法】git clone报错unable to access ‘xxx‘: SSL certificate problem:
网络·git·网络协议·ssl
等风来不如迎风去1 天前
【git】main|REBASE 2/6
git
艾伦~耶格尔1 天前
IDEA 配置 Git 详解
java·ide·git·后端·intellij-idea
云兮杜康1 天前
IDEA中用过git之后文件名颜色全变红
java·git·intellij-idea
睡不醒的小泽1 天前
git merge 和 git rebase
git
艾伦~耶格尔1 天前
Git 下载及安装超详教程(2024)
git·gitee·码仓