How do I get the hash for the current commit in Git?
2023-06-15
Question How do I get the hash of the current commit in Git? Answer To turn any extended object reference into a hash, use git-rev-parse: git rev-parse HEAD or git rev-parse --verify HEAD To retrieve the short hash: git rev-parse --short HEAD To turn references (e.g. branches and tags) into hashes, use git show-ref and git for-each-ref.
Difference between git stash pop and git stash apply
2023-06-14
Question I've been using git stash pop for quite some time. I recently found out about the git stash apply command. When I tried it out, it seemed to work the same as git stash pop. What is the difference between git stash pop and git stash apply? Answer git stash pop throws away the (topmost, by default) stash after applying it, whereas git stash apply leaves it in the stash list for possible later reuse (or you can then git stash drop it).…
git add only modified changes and ignore untracked files
2023-06-14
Question I ran "git status" and listed below are some files that were modified/or under the heading "changes not staged for commit". It also listed some untracked files that I want to ignore (I have a ".gitignore" file in these directories). I want to put the modified files in staging so I can commit them. When I ran "git add .", it added the modified files AND the files I want to ignore to staging.…
Keep file in a Git repo, but don't track changes
2023-06-14
Question I need to include some files in my GitHub repo, but not track changes on them. How can I accomplish this? An example use case is for a file that includes sensitive user information, such as login credentials. For example, I deploy a new installation of this framework to a new client, I want the following files to be downloaded (they have default values CHANGEME) and I just have to make changes specific to this client (database credentials, email address info, custom CSS).…
Add all files to a commit except a single file?
2023-06-12
Question I have a bunch of files in a changeset, but I want to specifically ignore a single modified file. Looks like this after git status: # modified: main/dontcheckmein.txt # deleted: main/plzcheckmein.c # deleted: main/plzcheckmein2.c ... Is there a way I can do git add but just ignore the one text file I don't want to touch? Something like: git add -u -except main/dontcheckmein.txt Answer git add -u git reset -- main/dontcheckmein.…
How to show the first commit by 'git log'?
2023-06-12
Question I have a Git project which has a long history. I want to show the first commit. How do I do this? Answer I found that: git log --reverse shows commits from start.
Show just the current branch in Git
2023-06-12
Question Is there a Git command equivalent to: git branch | awk '/\*/ { print $2; }' Answer $ git rev-parse --abbrev-ref HEAD master This should work with Git 1.6.3 or newer.