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

相关推荐
爱莉希雅&&&6 小时前
shell编程之awk命令详解
linux·服务器·git
baiyu336 小时前
成为git砖家(12): 看懂git合并分支时冲突提示符
git
wu_aceo10 小时前
将本地项目提交到Gitee
git·gitee·提交·本地提交·上传git
随便取个六字20 小时前
GIT操作 学习
git·学习
星源~1 天前
tree 命令集成到 Git Bash:可视化目录结构的指南
git·单片机·物联网·嵌入式·项目开发
zhaqonianzhu1 天前
git gerrit安装钩子
git·gerrit
这是个栗子1 天前
【问题解决】VSCode终端中看不到Git-Bash
ide·git·vscode
悲伤小伞1 天前
linux_git的使用
linux·c语言·c++·git
天机️灵韵1 天前
云效DevOps vs Gitee vs 自建GitLab的技术选型
git·开源项目
荔枝吻2 天前
【AI总结】Git vs GitHub vs GitLab:深度解析三者联系与核心区别
人工智能·git·github