惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

大猫的无限游戏
大猫的无限游戏
aimingoo的专栏
aimingoo的专栏
I
InfoQ
B
Blog RSS Feed
D
DataBreaches.Net
S
SegmentFault 最新的问题
P
Proofpoint News Feed
A
About on SuperTechFans
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
博客园 - 司徒正美
小众软件
小众软件
博客园 - Franky
有赞技术团队
有赞技术团队
D
Docker
T
Tailwind CSS Blog
雷峰网
雷峰网
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Blog — PlanetScale
Blog — PlanetScale
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog
V
Visual Studio Blog
宝玉的分享
宝玉的分享
爱范儿
爱范儿

jdhao's digital space

Conversion between base64 and OpenCV or PIL Image 腾讯云对象存储博客图床开启 CDN 加速(不需要购买额外域名) Search and Replace in Multiple Files in Vim/Neovim Change Table Column Width in LaTeX Image or Table Side by Side in LaTeX LaTeX 并排显示图像或表格 Firenvim: Neovim inside Your Browser Content inside HTML tags missing in Latest Hugo? Creating Markdown Front Matter with Ultisnips Labelme JSON 标注格式转 voc XML 格式 Nifty Nvim Techniques That Make My Life Easier -- Series 6 macOS 下如何为视频制作字幕 Running Command Asynchronously inside Neovim Resolving Merge Conflict after Git Stash Pop Pylint: command not found? A Hands-on Experience with Neovim's Built-in LSP Support How to Convert PDF to Images with Imagemagick 互联网上常用缩略语集锦 File Backup in Neovim Converting PDF Pages to Images with Poppler Nifty Nvim Techniques That Make My Life Easier -- Series 5 Neovim Configuration for System-wide Use How to sort a list of tuple or list in Python -- lambda or itemgetter? Building A Vim Statusline from Scratch 人类第一颗原子弹爆炸始末 Distributed Training in PyTorch with Horovod Learning Expect Programming Essential Knowledge about SSH Nifty LaTeX Techniques -- Series 1 更改 Adsense 邮寄地址,重新寄送 PIN
Git Learning Notes (4)
2021-11-27 · via jdhao's digital space

My Git learning notes.

Generate patch and apply it#

Sometimes, we need to develop the same project in different places, and in some place, we may not be convenient to push directly to the remote repo. We can generate a patch instead and apply the patch somewhere else.

First, run git diff > mypatch to generate a patch for the repo. To apply the patch somewhere, run git apply mypatch.

Ref:

Git: how to get out of detached head state#

In git, when we check out to a specific commit using git checkout <commit_id>, git warns us that:

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at 132ba1b... {some commit message}

Detached head means that we are current in no branch. To return to the previous branch we are in, use git checkout - or git checkout original_branch_name if you know the branch name.

Ref:

git: show commit that changes a specific file#

To show all commit that changes a specific file, use git log --follow -- file_path. --follow will track the commit that changes the file before its renaming, so it is highly recommended to include this option.

Ref:

use a git mirror site for cloning#

Due to access issues, sometimes we may want to use a github mirror service like fastgit. However, manually change the repo url from github.com to fastgit is not efficient enough. Fortunately, we can utilize the git url rewrite feature to achieve this globally. Run the following command:

git config --global url."https://hub.fastgit.xyz".insteadOf https://github.com

After that, when you clone a github repo, the actually url used will be the corresponding fastgit repo.

Ref:

Ignore a specific commit when blaming?#

Some commit may only change the format of a file, when doing git-blame, we may want to ignore such commits. We can use git blame --ignore-rev <commit-hash> to ignore a commit. Or, use git blame --ignore-revs-file ignore-file.txt, where ignore-file.txt contains a list of commits we want to ignore.

Ref: