Git notes
-- 2017-12-04 Monday - somvaar - सोमवार--
Git Notes
Contents
- 1 ^ OVERVIEW - अवलोकन
- 2 ^ Common Commands
- 3 ^ Git Commit Messages
- 4 ^ Git Command Examples
- 5 ^ Git Inner Workings
- 6 ^ Git Terminology
- 7 ^ Git Branching
- 8 ^ Git Merge
- 9 ^ Git Rebase
- 10 ^ Rebase versus Merge
- 11 ^ Git Diff and Related
- 12 ^ Git Tags
- 13 ^ Git stash - stash is global across branches
- 14 ^ Git log related
- 15 ^ Git remotes
- 16 ^ Using Git and Subversion Together
- 17 ^ Git For Windows notes
- 18 ^ References
^ OVERVIEW - अवलोकन
Following article / document collection of notes on version control software named git
. To learn git is not a gentle or short learning curve. This said, there are some key concepts worth mentioning at the beginning of a git learning journey. Some of these concepts include:
- https://nvie.com/posts/a-successful-git-branching-model/ git branching model and common git workflow in software development
- Zvonimir Spajic git internals trio of articles
- Zephyr Contributor Expectations good git practices highlighted in Zephyr RTOS Contributor Expectations document
- Most useful git commands - Orga.cat
- Basic git commands by Micheal Herman
- Example stash with helpful options: $ git stash save --include-untracked --keep-index
- https://www.atlassian.com/git/tutorials/merging-vs-rebasing . . . found by Rafael
- https://www.tutorialspoint.com/git/git_patch_operation.htm Git patch commands, found by Joel Hart
- https://help.github.com/en/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent . . . generate new key and add key to ssh-agent
- [1] git merging
- git merge and rebase commands
- git stage, commit, push on command line
- git 'commit' akin to traditional 'save file', Subversion model versus Git model
^ Common Commands
Wanting to understand and use git
better, here are some on-line references to git
version control. Noting here git reference at orga.cat, this reference well-written with lots of commands and concise explanations of each command. This reference is first in list:
Basic git commands:
2020-05-06
Atlassian article on Git's edit/stage/commit pattern of use (Invoke `git add` to stage local file changes.):
Setting up ssh key pairs for secure authentication:
Why are my local changes getting lost? Git commit-and-push-sequence not sufficient to transfer file changes to given git repository . . .
Git references found while answering specific git task questions:
$ git diff HEAD .
2022-01-10 Commands in `git` to rename local and remote branch:
ejemplo - board `anda-m`:
1 2003 git checkout andam-board-bring-up 2 2004 git branch -m anda-m-board-bring-up 3 2005 git branch 4 2006 git push origin -u anda-m-board-bring-up 5 2007 git push origin --delete andam-board-bring-up 6 2008 history
Markdown and .md file formatting at Github
Git and Working with Remote Repositories
Release tag creation and naming in Git
^ Git Commit Messages
Git Conventional Commits document, to aid in meaningful and searchable git commit messages. Link to standard here:
Git conventional commit messages have colon separated descriptors, the first of which are most standardized and narrow in count. These descriptors include:
- feat . . . feature
- fix
- "BREAKING CHANGE"
Some additional identifiers for types of code work committed in git tracked projects include:
- build
- chore
- ci . . . Continuous Improvement
- docs
- style
- refactor
- revert . . . when a commit reverts a previous commit
- perf . . . ??? performance enhancement ???
- test
Other commit note descriptors permitted as per the Angular Convention.
^ Git Command Examples
On the local work station, to see from which remote git repository a working copy comes:
$ git remote -v
A git invocation to perform pattern matching like `grep`:
$ git -C ../modules/hal/nxp/mcux/mcux-sdk grep -nC3 'FLASH_Init'
Within a git repository a developer may identify the full path to the repo or project root by issuing command:
$ git rev-parse --show-toplevel
A short form summary of commit messages with just the first line of each shown:
$ git log --oneline
An `ncurses` like character graphic tree representation of a repository's commit history:
$ git log --oneline --graph --all
Capture given git log to text file:
$ git --no-pager log > log.txt
Capture sets of changed files over a range of commits:
$ for hash in COMMIT_HASH_1 COMMIT_HASH_2 COMMIT_HASH_3; do git diff-tree -r $hash; done
To find out which files have changed in a given branch, call git this way:
$ git diff --name-only COMMIT_HASH_1 COMMIT_HASH_2
To see the changes in one file between two commits, call git with the 'diff' command and these four arguments:
$ git diff COMMIT_HASH_1 COMMIT_HASH_2 -- RELATIVE_PATH_AND_FILENAME
Note: the double dash '--' separates commit hash args from filenames, as commit hashes may number more than two.
^ Git Inner Workings
Key words: Three Places of Git : "Three Places of Git" : git tracked changes stored in three places
Good trio of articles by Zvonimir Spajic, on `git` inner workings, how git works under the hood. These tutorials also explain some important git terminology. Among the git details presented here Zvonimir explains that git "sees" a developer's changes in three places: working directory, staging directory and local repository. The staging directory contains a particular version controlled project's git index file. Staged but not committed changes are kept in this index file.
- https://konrad126.medium.com/https-medium-com-zspajich-understanding-git-data-model-95eb16cc99f5 . . . git data model
- https://konrad126.medium.com/understanding-git-branching-2662f5882f9 . . . git branching
- https://konrad126.medium.com/understanding-git-index-4821a0765cf . . . git index file
^ Git Terminology
What it means to 'rebase' in context of git . . .
* https://git-scm.com/docs/git-rebase
^ Git Branching
An official starting point for git branch use can be found at https://git-scm.com/docs/git-branch. Some articles on the large topic of best branching practices include:
- https://git-scm.com/book/en/v2/Git-Branching-Branching-Workflows
- https://dev.to/zenulabidin/git-branches-best-practices-46oo
- https://nvie.com/posts/a-successful-git-branching-model/ <-- This nvie.com article excellent git resource!
When there are local changes that haven't been committed . . .
* https://stackoverflow.com/questions/20568971/git-pull-keeps-telling-me-to-stash-local-changes-before-pulling
Excerpt from above link:
It sounds like your local branch does not have all of the changes on origin. Firstly, stash your changes git stash Then, pull in the changes from origin. git fetch origin && git rebase origin/(branch name) Next, add the stash back in to your working directory: git stash pop
2022
-
0526
-
When and why to delete older git branches . . .
-
ardalis replied:
[To delete git branches] won't impact git blame, since the commits are still present. Deleting a branch doesn't delete the commit history. A branch is basically just a pointer, pointing at a commit. Deleting the pointer leaves the commit intact.
To delete git tags . . .
-
To delete a remote tag:
Delete the tag locally, like above
-
git tag -d release/aug2002
git push origin :refs/tags/release/aug2002
0505
2021 Renaming local and remote branches:
0404
^ Git Merge
History re-writing git tools achieved through . . .
- https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History
- https://bohutskyi.com/mastering-git-commits-how-to-squash-and-simplify-your-history-d4b4a0f65864 Serhii Bohutskyi "How To Squash and Simplify Your History"
2023-07-12 git Kraken site:
^ Git Rebase
Intro to git rebase:
- https://medium.com/@slamflipstrom/a-beginners-guide-to-squashing-commits-with-git-rebase-8185cf6e62ec Sam Lindstrom "Beginner's Guide to git rebase..."
References to and notes on `git rebase` in this section, starting with a blog post about `git rebase --onto`:
2023 September needed to rebase a local branch to a remote branch, namely `main`, which git could not merge in its fast-forward mode. Found solution with git invocation:
$ git pull origin main --rebase
First created a second branch name pointing to same commit as local `main` HEAD. Then deleted the local main branch, but not sure now whether this step is necessary.
A good explanation of uses of `git rebase --onto commit1 commit2 [commit3]` by Enrico Campidoglio:
Git `rerere` - Reuse Recorded Resolution
Rebasing a branch with many commits beyond its present base commit sometimes leads to repeated conflicts, as each commit in the branch history is visited. This happens when local changes touch the same lines in the same files, between the local commits and the new base commit. The git command `rerere` stands for Reuse Recorded Resolution. It must be enabled with a global setting. (From following git article sounds as though it is disabled by default) Plus there is or are ways to use enable `rerere` per git repository, and not globally.
- https://git-scm.com/book/en/v2/Git-Tools-Rerere . . . author unknown
^ Rebase versus Merge
stub section
^ Git Diff and Related
Git difference command `git range-diff` available on Ubuntu like systems via package `git-extras`. An introductory article on basic use of `range-diff` command:
Git's range-diff command may also take arguments of the form:
$ git range-diff $common_base $start_of_first_commit_series $start_hash_of_second_commit_series
^ Git Tags
Command `git show <tag_name>` . . .
A few `git tag` command uses:
$ git tag
$ git tag --delete <tag_name>
$ git tag -a <tag_name> -m "tagging message here" [optional_commit_hash]
^ Git stash - stash is global across branches
Note that git stash "entries" are global across branches.
Some common uses of `git stash`:
$ git stash --keep-index --include-untracked # . . . to create a stash entry for the present branch (NEED in-page anchor to 'git index' terminology - TMH) $ git stash list # . . . list stash entries for present branch $ git stash list --all # . . . list stash entries for all branches of present local repository
Keywords: git log pickaxe option
A git conventions / best practices article, specific conventions for git commit messages:
Ways to invoke `git log`:
- https://opensource.com/article/21/4/git-whatchanged `git log --raw`, `git log --patch` and `git whatchanged`.
Git's string search parameter or "pickaxe" log option `-S`:
At the command line in a color supporting terminal window, the following `git` invocation produces a useful tree like representation of local and remote branches:
$ git log --oneline --graph --all
^ Git remotes
Working with multiple git remotes , remote repositories. The following tutorial link to Jigarius leads to a good article. In attempting to set up a local git remote 'definition' with two remote URLs, it became clear that there are issues that break this effort when one remote repo is already created and has pre-existing history. It doesn't matter how short or simple that history is. So this is a good link, but may not be practical to set up multiple remotes to be updated with a single 'push' command when the remotes are not all fully under a given developer's control:
So another question which this prompts, this being the effort to push local work to multiple remotes, is: how does git handle symbolic links? Links at least in the Unix and Linux context?
On git handling of symlinks:
Adding ssh keys to ssh-agent, listing ssh keys, configuring multiple github emails:
How to list git configuration:
$ git config --list
How to modify remote repository URL:
$ git remote set-url origin git@github.com:[github_account_username]/[repository_name]
. . . this information thanks to post at https://stackoverflow.com/questions/2432764/how-do-i-change-the-uri-url-for-a-remote-git-repository.
^ Using Git and Subversion Together
Using Git and Subversion on one and the same project looks complicated . . .
^ Git For Windows notes
Looks like with latest (as of 2021-06-16) Git For Windows offers three different ways to configure credentials management. This seems important, here is a link provided by the Git-for-Windows installer:
Locally installed release notes at: file:///C:/Users/<user_name>/AppData/Local/Programs/Git/ReleaseNotes.html
^ References
Git fetch and merge preferrable to git pull . . .
Note: in Firefox 89.0.1 (64-bit) the key binding <CTRL>+j opens a message box showing download progress and history.