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

推荐订阅源

H
Hackread – Cybersecurity News, Data Breaches, AI and More
U
Unit 42
Vercel News
Vercel News
Martin Fowler
Martin Fowler
云风的 BLOG
云风的 BLOG
爱范儿
爱范儿
MongoDB | Blog
MongoDB | Blog
J
Java Code Geeks
F
Fortinet All Blogs
MyScale Blog
MyScale Blog
C
Check Point Blog
N
Netflix TechBlog - Medium
Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏
博客园_首页
WordPress大学
WordPress大学
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
Last Week in AI
Last Week in AI
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
Jina AI
Jina AI
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 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 Mintty Tips and Configurations
Resolving Merge Conflict after Git Stash Pop
2019-12-03 · via jdhao's digital space

Sometimes, when we are working with our local changes in a Git repo, we may want to pull the latest updates from the remote repository. To avoid code conflict between remote files and local files. We can use git stash to store the unfinished local work temporarily.

Git-stash gives you a clean repo and revert the repo state to last commit. Then we can use git pull to pull the updates.

Git stash basic knowledge#

Stashed changes are per repository, not per branch.#

If you are in a certain branch and do a git stash, you may think that the stashed changes only belong to that branch. However, that is not the case. Since you have not committed the changes, they do not belong to any branch, even if you are currently working on a specific branch (see here).

Show stashed changes#

To show stashed changes, use git stash list. It will show a list of stash you have made.

Show the detailed info of a particular stash#

Each stash in the stash list can be referenced by its number. To show changes in a particular stash, we can use the following command:

# show changes in the first stash
git stash show stash@{0}

The above command only shows summary changes to files in a stash. To show detailed changes of a stash, add the -p option:

git stash show -p stash@{0}

Applying git stash#

After the git-pull, we may want to continue our unfinished work. We can use git stash pop to restore unfinished work. You can also use git stash apply instead. The difference between git stash pop and git stash apply is that the former will drop the stash if there is no merge conflict, while the later will never drop the stash even if the stashed changes merge successfully with the pulled code.

Anyway, if everything goes well, our unfinished changes can merge with the remote updates without any conflict. However, if we and other collaborator both have changed the same file at the same place, we will encounter merge errors after git-stash. The error message is like the following:

Auto-merging test.txt
CONFLICT (content): Merge conflict in test.txt
The stash entry is kept in case you need it again.

Conflict markers#

When we open the conflict file, we will see some markers like the following:

abc
<<<<<<< Updated upstream
qwe
=======
lmn
>>>>>>> Stashed changes

These markers are called conflict markers, which are used to indicate the conflicting changes made to a file.

In the git-stash case, code between <<<<<<< and ======= are the changes made upstream, and code between ======= and >>>>>>> are your stashed changes.

To merge the conflict, you have basically two methods:

  • Resolve the conflict manually: decide if you want your change or the upstream change or you want to combine the local and remote change. Then edit the file accordingly and remove those conflict markers.
  • Resolve the conflict with mergetools. See here for an introduction.

Mark conflict as resolved#

After resolving the conflict, you can use git add to mark the conflict as resolved. But in the git-stash scenario, you may not want to do this since your changes are not finished yet.

Or you can use git reset to mark that the conflict has been solved. You can continue working on your project until your changes are completed, and then commit your changes.

After the conflict has been resolved, do not forget to use git stash drop to drop the stash because the stash will not be dropped automatically in case of a merge conflict.

References#