git commands
About git
Version control software, such as git
, is an important tool for programming. Git allows you to keep track of what you did when, undo any changes you have decided you don't want, and collaborate at scale with other people.
For details, see wiki document "Version Control with git", and the official Git documentation (opens new window), the "git book".
Local .git/config file
First of all, take a look at file .git/config
. This file often contains important customizations that hold for the current project. You should know that many of these entries might modify the commands shown below. And there might be a lot of these customizations.
The most important git
commands are listed here, but they are not necessarily always applied in this order.
Most common git commands
Read-Only Commands
Getting the current state of the repository
git status
git log -5
- show last 5 commits (date, id and message)git log <path> -5
- show last 5 commits of a single file/path (with hashes)git log --pretty=format:"%h %ad | %C(yellow)%s%d%Creset %C(cyan)[%an]%Creset %Cgreen(%cr)%Creset" --date=short
- show on one line, coloredgit diff <filename>
- compare changed file with last committed version in repogit diff hash1..hash2 <filename>
- display changes between older versions
Managing local changes
These commands do something to your local repository.
Adding things:
git add .
- add everything what's new or changed to the "index" of the repositorygit commit -m "an informative message"
- really make contents of "index" persistent and traceable
Undoing changes:
A single file:
git checkout <filename>
- restore latest committed version from repository, overwriting current file
Keeping two versions in parallel:
git branch
- create a branch (locally)git checkout <branchname>
- change current "working directory" tobranchname
git merge <frombranch> <tobranch>
- keeps perfect traceabilitygit pull --rebase
- get most recent changes and "flatten" the graphgit push --force
- send the rebased, simplified graph to remote repo. Must force
Less important
Less important or common commands, also for managing local changes
git init
git version
git ignore *.pdf
- (in pkg "git-extras") do not put PDF files under version control.
Working with a remote repository
git clone
- download and make first copy of remote branchgit fetch
- refresh metadata info. check what's new remotely (but don't apply changes)git pull origin master
- get changes from remote master branch and apply them to local branchgit push
- upload changes to 'origin' repogit diff --check
- show files with leftover conflict markers (see also: bottom of page)
git Commands for mDIS
It is impossible to describe a recipe here that can be used under all circumstances. Often the sequence of commands is highly specific and depends on what you need to achieve.
TBC
git commands combined with other unix tools
git diff --check | perl -pE "s/:\d+:/:/g" | sort -u
- display unique filenames with merge conflict markers
git diff --check | perl -pE "s/:\d+:/:/g" | sort -u | wc -l
- count number of unique conflicted files