Branch from a previous commit using Git
2022-03-18
Question If I have N commits, how do I branch from the N-3 commit? Answer Create the branch using a commit hash: git branch branch_name <commit-hash> Or by using a symbolic reference: git branch branch_name HEAD~3 To checkout the branch while creating it, use: git checkout -b branch_name <commit-hash or HEAD~3>
How do I update the password for Git?
2022-03-18
Question I'm using BitBucket with Xcode and Git for version control, and recently I changed all of my passwords (thanks Adobe!). Unsurprisingly, I'm no longer able to push my local commits to my repository on BitBucket (Authentication failed for 'https://______.git'), but I'm forgetting how to update the cached password on my iMac. Somehow I've been unable to find it on Google or Stack Overflow, though it seems to me it should be rather straightforward.…
How to show Git log history (i.e., all the related commits) for a sub directory of a Git repository
2022-03-18
Question Let’s say that I have a Git repository that looks like this: foo/ .git/ A/ ... big tree here B/ ... big tree here Is there a way to ask git log to show only the log messages for a specific directory? For example, I want to see what commits touched files in foo/A only. Answer From directory foo/, use git log -- A You need the '--' to separate <path>.…
Is there a way to "autosign" commits in Git with a GPG key?
2022-03-17
Question Is there an easy way to make Git always signs each commit or tag that is created? I tried it with something like: alias commit = commit -S But that didn't do the trick. I don't want to install a different program to make this happen. Is it doable with ease? Just a side question, maybe commits shouldn't be signed, only tags, which I never create, as I submit single commits for a project like Homebrew, etc.…
git remote add with other SSH port
2022-03-16
Question In Git, how can I add a remote origin server when my host uses a different SSH port? git remote add origin ssh://user@host/srv/git/example Answer You can just do this: git remote add origin ssh://user@host:1234/srv/git/example 1234 is the ssh port being used
How do I see the differences between two branches?
2022-03-16
Question How do I see the differences between branches branch_1 and branch_2? Answer Use git diff. git diff [<options>] <commit>..<commit> [--] [<path>…] <commit> is a branch name, a commit hash, or a shorthand symbolic reference. Examples: git diff abc123..def567, git diff HEAD..origin/master. That will produce the diff between the tips of the two branches. If you'd prefer to find the diff from their common ancestor to test, you can use three dots instead of two:…
How to remove origin from git repository
2022-03-16
Question Basic question: How do I disassociate a git repo from the origin from which it was cloned? git branch -a shows: * master remotes/origin/HEAD -> origin/master and I want to remove all knowledge of origin, and the associated revisions. Longer question: I want to take an existing subversion repo and make a number of smaller git repos from it. Each of the new git repos should have the full history of just the relevant branch.…