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

推荐订阅源

H
Help Net Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
Microsoft Azure Blog
Microsoft Azure Blog
Google DeepMind News
Google DeepMind News
Apple Machine Learning Research
Apple Machine Learning Research
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
爱范儿
爱范儿
L
LangChain Blog
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
MongoDB | Blog
MongoDB | Blog
Hugging Face - Blog
Hugging Face - Blog
G
Google Developers Blog
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
宝玉的分享
宝玉的分享
博客园 - 三生石上(FineUI控件)
D
DataBreaches.Net
Recent Announcements
Recent Announcements
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

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 (3)
2021-02-17 · via jdhao's digital space

Git learning notes.

fatal: no files added#

When I add files under a directory using git add some_folder/*, I see the following error message:

The following paths are ignored by one of your .gitignore files:
ppt/__pycache__
Use -f if you really want to add them.
fatal: no files added

This is because * is interpreted by the system, so it will add all files under a directory. If some files under this directory are in the .gitignore, you will see the above error message.

Ref:

git ask for username and password each time I push#

I cloned a remote repo using https protocol. Each time when I push to this repo, git asks me to enter my username and password. This is annoying.

To prevent from entering username each time, we can add username to remote repo url like this:

git remote set-url origin https://jdhao@github.com/jdhao/toy_project.git

where jdhao is my username. In this way, we do not need to enter username when we push to remote. In fact, we can provide the password after the username like this:

git remote set-url origin https://jdhao:some_pwd@github.com/jdhao/toy_project.git

However, it is not safe to do so, since your password are stored in plain text now.

For password, if we are in Linux, we can use the following settings:

git config --global credential.helper 'cache --timeout=3600'

The password will be cached in memory for 3600 seconds, which means that you do not need to input password for 1 hour. Tweak the time interval to suit your need.

Ref:

Compare same file from different branches#

Sometimes, I want to see the difference of a file on different branches. For example, to find the difference for foo.py on master and dev branch. There are two slightly different ways to do this.

git diff master..dev path/to/foo.py
git diff master dev -- path/to/foo.py

or

git diff master:path/to/foo.py dev:path/to/foo.py

Ref:

Clone a git repository without history?#

Due to slow networking speed or other reasons, we may want to clone a repository without its huge history. We can use --depth to restrict the number of history to include, --depth 1 will only clone the last commit, effectively meaning that no history is cloned.

git clone --depth 1 http://url/to/git/project

Ref:

How to check last commit for a given line only?#

By default, git-blame will print out the last commit info for each line in a file. What if we are only interested in a particular line range? In this case, we can use -L to restrict the line range. For example, if I want to blame line 4-5 for file options.vim, I can use the following command:

git blame -L 4,5 core/options.vim

Ref: