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 入门

相关推荐
golang学习记2 分钟前
Facebook 为什么不用 Git?
git·elasticsearch·facebook
GIS阵地32 分钟前
git拉取时报错
大数据·git·elasticsearch
无限进步_3 小时前
C++ Vector 全解析:从使用到深入理解
开发语言·c++·ide·windows·git·github·visual studio
charlee443 小时前
Git使用经验总结9-Git提交关联到Issue
git·issue
-拟墨画扇-4 小时前
Git | Bug分支操作
git·gitee·github·bug·gitcode
-拟墨画扇-6 小时前
Git | Feature分支操作
git·gitee·github·gitcode
无限进步_6 小时前
C++多态全面解析:从概念到实现
开发语言·jvm·c++·ide·git·github·visual studio
henreash6 小时前
windows下git的hooks
git
无限进步_6 小时前
C++ STL list容器深度解析与模拟实现
开发语言·数据结构·c++·windows·git·list·visual studio
爱码小白21 小时前
GIT版本控制
git