See the real details of a git commit

The command to see the details of a git commit, specifically the tree attached to it, is:

git cat-file -p HEAD

It produces an output like this:

jason@rise22:~/code/appcove/HKSickler$ git cat-file -p HEAD
tree f388dffd7ac29813d4a61a1cfd9f4a03518c3c56
parent 2752fafb51cb58c288adcd5d0a6f262943416683
parent cd6ce6f905ef61d019fbbd16e157ef0389f809ef
author Jason Garber <jgarber@appcove.com> 1669396739 -0500
committer Jason Garber <jgarber@appcove.com> 1669396739 -0500

Merge: merge this and that ....

git checkout -b –no-track

Ever want to checkout a new git branch from another branch without setting up tracking?

Here is the longhand way:

git checkout old-branch
git branch new-branch
git checkout new-branch

But there is a quicker way:

git checkout -b new-branch old-branch

… which does the same thing, albiet in one command.

How to checkout and track a remote git branch

One of those really handy things to remember…  When git “tracks” a branch, it basically sets up an entry in .git/config which tells git what to do with push and pull.  For example:

I had a remote branch called Task/Round3.3.

I wanted to work on it locally, but have push and pull work right.

So I ran this:

git checkout -b Task/Round3.3 --track origin/Task/Round3.3

To which git said:

Branch Task/Round3.3 set up to track remote branch refs/remotes/origin/Task/Round3.3.
Switched to a new branch "Task/Round3.3"

And in .git/config, these lines were added:

[branch "Task/Round3.3"]
remote = origin
merge = refs/heads/Task/Round3.3

Now, when I checkout Task/Round3.3, I am able to say `git pull` and `git push`, and it will do the “right thing”…

git add -u

Here is a nice little tidbit I ran across some time ago…  Ever delete a bunch of files from a git working copy, and then had to go in and tell git that you meant to delete them?  For example:

[jason@dc40 AppStruct]$ git status
# On branch master
# Changed but not updated:
#   (use "git add/rm ..." to update what will be committed)
#
#       deleted:    Python/AppStruct/Application.py
#       modified:   Python/AppStruct/Database/PostgreSQL.py
#       deleted:    Python/AppStruct/Date.py
#       deleted:    Python/AppStruct/JSON.py
#       deleted:    Python/AppStruct/Util.py
#       deleted:    Python/AppStruct/__init__.py
#
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
#       Python/AppStruct/NewFile.txt
no changes added to commit (use "git add" and/or "git commit -a")

Previously, the way to handle this would be:

   git rm ...
   git rm ...
   git rm ...
   git rm ...
   git rm ...
   git add ...
   git add ...

Rather, isn’t this easier?

   git add -u
   git add .

From the man page for git-add:

–update | -u
Only match against already tracked files in the index rather than the working tree. That means that it will never stage new files, but that it will stage modified new contents of tracked files and that it will remove files from the index if the corresponding files in the working tree have been removed.