- Git - misc notes/tips
git branch --move old_branch new_branch
git checkout new_branch
git push --set-upstream origin new_branch
git push origin --delete old_branch
git tag -l
git show TAG_NAME
git log --oneline -n 5
- assuming that five lines is enough to spot the commit you want to tag, which is usually a merge commit
git tag -a v0.1.5 -m "Tagging v0.1.5" GIT_COMMIT_HERE
- Push the tag(s)
- All tags:
git push origin --tags
- Just the one:
git push origin TAG_NAME
- All tags:
git push origin :TAG_NAME
git push -d TAG_NAME
git push --delete origin TAG_NAME
git tag --delete TAG_NAME
git diff COMMIT~ COMMIT
git show COMMIT
git log -p c -1
seems to do the same thing
git diff COMMIT^!
git diff-tree -p COMMIT
git show HEAD~1
git show --name-only COMMIT
git diff-tree --no-commit-id --name-only -r COMMIT
-
git log --all --decorate --oneline --graph
- Short commit hash
- One line log summary
- graph showing branch merges/activity
-
git log --graph --abbrev-commit --decorate --date=relative --all
- lists a graph alongside the normal/detailed log output
- TODO: List what the other options do
-
git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
- TODO: Add description
git branch -vv
- shows info for all branches
Example output:
$ git branch -vv
* initial-dev-env-work e34d574 [origin/initial-dev-env-work] Initial version of mysql2sqlite-dev project
master 14e28a5 [origin/master] Initial commit
cat .git/config
- tip: look for
[branches]
- tip: look for
git checkout BRANCH_NAME
git branch --set-upstream-to REMOTE/BRANCH_NAME
Assuming that pushing changes to the remote is OK, this seems to do the trick:
git push origin -u --all
Example output:
Everything up-to-date
Branch 'initial-dev-env-work' set up to track remote branch 'initial-dev-env-work' from 'origin'.
Branch 'master' set up to track remote branch 'master' from 'origin'.
git commit --amend --date=now
placeholder
git commit --amend --reset-author --no-edit
This resets commit author values using the information specified by
git config user.name
and git config user.email
.
git filter-branch -f --env-filter "
GIT_AUTHOR_NAME='Newname'
GIT_AUTHOR_EMAIL='new@email'
GIT_COMMITTER_NAME='Newname'
GIT_COMMITTER_EMAIL='new@email'
" HEAD
This approach is useful if you want to setup a build system that requires read-only access to a restricted repo. Instead of hard-coding your main set of credentials (which are likely protected by 2FA), you can often request an API key via the web UI for select repo operations.
- Create
$HOME/.netrc
- Enter
machine
,login
andpassword
details - Test!
Example contents:
machine example.visualstudio.com
login bob
password afg87afg8a7fga8sfg78afga8fgafs8dgsdfagxgcxcfgfrg87as
git clone
operations should work as expected without prompting for
credentials.
-
https://stackoverflow.com/questions/4847101/git-which-is-the-default-configured-remote-for-branch
-
https://stackoverflow.com/questions/9110310/update-git-commit-author-date-when-amending
-
https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/
-
https://stackoverflow.com/questions/4082126/git-log-of-a-single-revision
-
https://stackoverflow.com/questions/17563726/how-to-see-the-changes-in-a-git-commit