====== Doing things with git ======
Git has become probably the most popular source-control system today, and if you're new to it, or don't use it very often, there are some things you might want to do which seem simple, but you just can't remember or work out the required command.
I think git is an unpleasantly inconsistent collection of tools and commands which disappointingly failed to learn from the disparate and sometimes conflicting options to other command-line utilities (for example, does **-n** mean "add line numbers to the output" [grep, cat] or does it mean "just do a dummy run; change nothing" [rsync, rename], or does it mean "display IP addresses and port numbers instead of host names and protocol names" [netstat, iptables]?). Linus had the opportunity to create a new family of tools which behaved in a way people could understand and remember, but he probably just never used DEC VMS and therefore didn't realise there was a better way of doing things than how Unix does it.
So, guides like this are necessary. This is a summary of things you are likely to want to do with git, and how to do them, for the times when you can't remember, have never needed to do them before, or are simply baffled by the inconsistency of how git works.
===== How to find out... =====
==== ...which branch I’m currently looking at / working in? ====
git status
* It’s important to know which branch any edits, **git add**s, **git commit**s or **git push**es are going to affect!
==== ...which files are affected by a commit? ====
git show --name-only
* Lists the filenames affected by the commit
git show --name-status
* Lists the filenames affected by the commit, and also shows whether they were **A**dded, **M**odified, **D**eleted or **R**enamed (moved)
==== ...which files have been affected since a commit? ====
git show --name-only ..
* Lists the filenames affected since the commit
git show --name-status ..
* Lists the filenames affected since the commit, and also shows whether they were **A**dded, **M**odified, **D**eleted or **R**enamed (moved)
==== ...which commits have affected a file? ====
git log --follow
==== ...what commits have taken place since a specific commit? ====
git log ..
==== ...what commits are in a different branch from the one I’m working in? ====
git log
==== ...what actual changes are in a commit? ====
git show
* There are many options for the git show command, use git help show to find out more
* This command generates essentially the same output as //git diff // (see below) when reference 2 immediately precedes reference 1
==== ...what the differences in a file between two commits are? ====
git diff
or
git diff ..
==== ...what the differences in a file between two branches are? ====
git diff : :
* This will show the differences in the specified file between the version in branch 1 and the version in branch 2.
* You do not have to have either of these branches currently checked out.
==== ...which files differ between two branches? ====
git diff : : --name-status
* You do not have to have either of these branches currently checked out.
==== ...what does a file look like in another branch or commit? ====
git show :
git show :
==== ...all differences between two branches? ====
git diff : :
==== ...all differences between two commits? ====
git diff
* This command generates essentially the same output as //git show // (see above) if reference 1 immediately follows reference 2.
==== ...which files contain conflicts after doing a merge? ====
git diff --name-only --diff-filter=U
* This will list the files which contain conflicts
git diff --name-status --diff-filter=U
* This will list the files and almost certainly always show **U** for **U**pdated
git diff --diff-filter=U
* This will show the differences (ie: the areas of conflict) in the files
----
[[.:|Go up]]\\
Return to [[:|main index]].