git
This is the git command for managing source code, which is useful from the GUI but even more useful and faster if you learn the commands.
You can use it from the GUI, but it’s more convenient and faster if you learn the commands. There are many ways to use git on the net, so I’ll focus on the commands I use here.
NAME
git - the stupid content tracker
SYNOPSIS
git [--version] [--help] [-C <path>] [-c <name>=<value>]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|-P|--no-pager] [--no-replace-objects] [--bare]]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
[--super-prefix=<path>]
<command> [<args>]]
github
- The file in jupyter notebook format on github is here .
google colaboratory
- To run it in google colaboratory here git_nb.ipynb)
environment
My OS is macOS, and the options are different from those of Linux and Unix commands.
When you actually run the command, you will need to use the prefix ! and %%bash in the first line.
!sw_vers
ProductName: Mac OS X
ProductVersion: 10.14.6
BuildVersion: 18G2022
!bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18)
Copyright (C) 2007 Free Software Foundation, Inc.
Example usage
The following is a list of frequently used command combinations.
[git add] Add a file diff to the index.
git add -h
usage: git add [<options>] [--] <pathspec>...
-n, --dry-run dry run
-v, --verbose be verbose
-i, --interactive interactive picking
-p, --patch select hunks interactively
-e, --edit edit edit current diff and apply
-f, --force allow adding otherwise ignored files
-u, --update update tracked files
--renormalize renormalize EOL of tracked files (implies -u)
-N, --intent-to-add record only the fact that the path will be added later
-A, --all add changes from all tracked and untracked files
--ignore-removal ignore paths removed in the working tree (same as --no-all)
--refresh don't add, only refresh the index
--ignore-errors just skip files which cannot be added because of errors
--ignore-missing check if - even missing - files are ignored in dry run
--chmod (+|-)x override the executable bit of the listed files
[git status] Check the current status.
git status
Reminder.
This is a command that I use a lot, but often forget. I use it a lot for code reviews.
Diff between branches
You can now check your diffs with vimdiff, which is the default setting. You need to set the diff default to vimdiff in your .gitconfig.
git difftool branchA branchB
Diff between commits (file names only)
Check for differences in files by commit ID.
git diff --stat shaA shaB
Differences between commits (each file)
It’s really useful to be able to see the diffs with vimdiff
git difftool -y shaA shaB -- <FILE NAME>