====== Git versioning short how-to ======
===== General =====
* Show all files in repo:
git ls-files
* Show all config files:
git config --list --show-origin
* Example output of above command:
file:/Users/dani/.gitconfig diff.renames=true
file:/Users/dani/.gitconfig user.name=Daniel Steiner
file:/Users/dani/.gitconfig user.email=daniel.steiner@greenmail.ch
file:/Users/dani/.gitconfig help.autocorrect=1
file:/Users/dani/.gitconfig color.ui=true
file:/Users/dani/.gitconfig pager.diff=diff-so-fancy | less --tabs=4 -RFX --pattern '^(Date|added|deleted|modified): '
file:/Users/dani/.gitconfig alias.patch=!git --no-pager diff --no-color
file:.git/config core.repositoryformatversion=0
file:.git/config core.filemode=true
file:.git/config core.bare=false
file:.git/config core.logallrefupdates=true
file:.git/config core.ignorecase=true
file:.git/config core.precomposeunicode=true
file:.git/config remote.origin.url=ssh://dev.dsteiner.ch/srv/git/kvm.git
file:.git/config remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
file:.git/config branch.master.remote=origin
file:.git/config branch.master.merge=refs/heads/master
* An example of ''$HOME/.gitconfig'' file:
# Our diff algorithm
[diff]
# external = /usr/local/bin/ksdiff
# external = /opt/local/bin/icdiff
renames = true
[user]
name = Daniel Steiner
email = daniel.steiner@greenmail.ch
[help]
autocorrect = 1
[color]
ui = true
[pager]
diff = diff-so-fancy | less --tabs=4 -RFX --pattern '^(Date|added|deleted|modified): '
[alias]
patch = !git --no-pager diff --no-color
==== Local states ====
* List files in local repository
git ls-files -m -d -u -c
|-m|Show modified files in the output |
|-d|Show deleted files in the output |
|-u|Show unmerged files in the output (forces --stage)|
|-c|Show cached files in the output (default) |
==== Remote branches ====
* List all remote branches and their states:
git remote -v update
Fetching origin
From ssh://dev.dsteiner.ch/srv/git/shell
= [up to date] master -> origin/master
= [up to date] from_svn -> origin/from_svn
||This deletes all ''*.scpt'' files from git, but not from filesystem!|
* Corresponding ''.gitignore'' file:
*.scpt
|**Note:**|This is usefull, if you add some new ignores which where already checked in into git!|
==== Git cache ====
* Deleting cache for all ''scpt'' extensions (current directory!):
git rm --cached *.scpt
|**Note:**|Everything is up to date here!|
===== Search in log =====
* Searching for all changes in example.txt file:
git log --follow example.txt
* Output of search:
1e733 Fact regular expression replaced by YAML configuration array
c5af0 Ingoring host, if no facts gotten from Satellite, hoios-6.9 added in config
c9f856 op5server multidimensional array added, script checks now for this op5 servers.
b67b7f2 Now, the hilti_hiera_tier fact must match for the host sync
a794cb6 All Windows line feeds are now in UNIX format
f818aa5 YAML configuration definition changed from hostgroups to os_to_hostgroups
cced6b2 Now hostgroups are supported for changes. New config section added in YAML files for the hostgroups
f97ea6 Init of all my scripts
* Show the first 8 log entries (commits):
git log --oneline master~8..master
56ec4 History setting changed.
a1e8076 Check for directory added.
b9ba4c2 New script for pushing ahead versions to server
a2c1f Tarball creation fixed (excludes)
4172a New script for homedir symlinks to BigLacie
ba549a2 Keep days now 7
96f7f New Twig syntax file for Twig extention
02d81 Improvements in bolt scripts for backup and update/install
* Show the commits from the third to fifth:
git log --oneline master~5..master~2
b9ba4c2 New script for pushing ahead versions to server
a2c1f Tarball creation fixed (excludes)
4172a New script for homedir symlinks to BigLacie
===== Diffing =====
* Show diff of given two version for a file:
git diff -r 55c5af0 cced6b2
* The same, but showing diff(s) in a configured difftool:
git difftool -r 55c5af0 cced6b2
* Show staged files(s) diffs:
git diff --cached
===== Patching =====
If you want to generate a patch for any changes from any previous commit, you can use ''%%git log%%'' to list it.
|**Note:**|You can limit the patch output for a limited number of commits (''%%-1%%'', ''%%-2%%'', …)|
* Show log and the path for one commit (-1):
git log -1 -p --follow profile/.vimrc
* Show log and the path for two commit, between commits //8b808f3// and //496f837//:
git log -2 -p 8b808f3 496f837 --follow profile/
commit 8b808f3226fa7c72f24725c401e5789a1423ebd1
Author: Daniel Steiner
Date: Fri Mar 31 13:23:07 2017 +0200
History variables only exported ones
diff --git a/profile/.danirc b/profile/.danirc
index ffe1c4b..e4f06b9 100644
--- a/profile/.danirc
+++ b/profile/.danirc
@@ -47,6 +47,7 @@ fi
export PERLIO=stdio
# history in bash options:
shopt -s histappend
-export HISTSIZE=10000
-export HISTCONTROL=erasedups
-export HISTTIMEFORMAT='[%d.%m.%Y-%T] '
+HISTSIZE=10000
+HISTCONTROL=erasedups
+HISTTIMEFORMAT='[%d.%m.%Y-%T] '
+export HISTSIZE HISTCONTROL HISTTIMEFORMAT
commit d1f35258ea458bbd8c3ad581a5302f99ff5d12a3
Author: Daniel Steiner
Date: Thu Mar 30 15:32:28 2017 +0200
History time added
diff --git a/profile/.danirc b/profile/.danirc
index d18ac8f..ffe1c4b 100644
--- a/profile/.danirc
+++ b/profile/.danirc
@@ -49,3 +49,4 @@ export PERLIO=stdio
shopt -s histappend
export HISTSIZE=10000
export HISTCONTROL=erasedups
+export HISTTIMEFORMAT='[%d.%m.%Y-%T] '
===== Get a file from different branch =====
It’s possible to get a file from a different branch or checkin. First go into the directory and branch, you want to add or change the file. Now, you can get the content of the desired file:
* Get the file from commit //8b808f3//:
git checkout 8b808f3 (1)
git checkout / (2)
|**1**|Using a commit id |
|**2**|Using another branch|
|**Note:**|This is only working, if the path in repository is the same!|
* To get the content and write that into a file, use this command:
git show 8b808f3: >
* To list, which is the proper file and path, use ´ls-tree´:
git ls-tree -r --name-only 8b808f3
profile/git-needs-action.sh
profile/multitail-emerge.conf
profile/multitail.conf
ps3videoenc.sh
===== Restore a differen version of a file =====
Sometimes you need to get an older version of a file. Here this procedure is shown.
* Get the proper commit hash:
git log --oneline --follow scss/_settings.scss
c5b0c96 First green layout finished
36614 Daily work finished
bec017 Initial setup including script to get no git managed files from owncloud folder
Assuming, you want to get the version of hash ''%%8bec017%%''.
* Restoring defined version of file:
git checkout 8bec017 -- scss/_settings.scss