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 the wiki document "Version Control with git", and the official Git documentation, the "git book".
Local .git/config file
First of all, take a look at the 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 the last 5 commits (date, id, and message)git log <path> -5
- show the 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 the last committed version in the 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 that's new or changed to the "index" of the repositorygit commit -m "an informative message"
- really make the contents of the "index" persistent and traceable
Undoing changes:
A single file:
git checkout <filename>
- restore the latest committed version from the repository, overwriting the current file
Keeping two versions in parallel:
git branch
- create a branch (locally)git checkout <branchname>
- change the current "working directory" tobranchname
git merge <frombranch> <tobranch>
- keeps perfect traceabilitygit pull --rebase
- get the most recent changes and "flatten" the graphgit push --force
- send the rebased, simplified graph to the 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 the first copy of the remote branchgit fetch
- refresh metadata info. check what's new remotely (but don't apply changes)git pull origin master
- get changes from the remote master branch and apply them to the local branchgit push
- upload changes to the '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 the number of unique conflicted files