Git

List of Repository Changes

Changes in git are commits, the command below shows the commit tag and commit message.

git log --oneline

Retrieve Past Commit Info

Use the Git commit tag. See the Print a List of Repository Changes section to get a list of commit tags.

git show f814dd7

Undo a Git Commit

git revert f814dd7

Create a new Branch

git checkout -b textual-snake

Merging a Branch

Assuming you are on the project_webite_updates branch:

$ git branch
db4e-os
main
* project_website_updates

Then:

git checkout main
git merge project_website_updates
git push origin main

Delete a Branch

To delete a branch you have in your local repo:

git branch -d project_website_updates

To delete a branch you don’t have in your local repo, but is in the remote repo:

git push origin --delete project_website_updates

Doing a Release

git add .
git commit -m "Your commit message"
git tag -a v0.15.8 -m "Release v0.15.8"
git push origin main --tags

Change to a Branch

git checkout new_branch

Checkout by Commit Tag

git checkout a1e8fb5

Clone a repository

git clone git@github.com:NadimGhaznavi/db4e

Another example, cloning the Monero XMR’s P2Pool software by SChernykh, but this time we also clone any 3rd Party software which the build depends on. A software build may fail without the --recursive switch.

git clone --recursive https://github.com/SChernykh/p2pool

Clone a Repo Wiki Site

git clone git@github.com:YOUR_USERNAME/YOUR_REPOSITORY.wiki.git

Setup SSH Authentication

git remote set-url origin git@github.com:NadimGhaznavi/kb.wiki.git

Dealing with a Bad Commit

Finding which Commit for a File

git log --oneline -- test_logs/p2pool.log

Sample output:

96293b8 feat: P2Pool log watcher

Commit History

We need to figure out where in the commit history that commit happened:

git log --oneline

Sample output:

b996205 (HEAD -> feature/p2pool-stdin) chore: add sample logs
fdc79d5 chore: ignore test_logs directory
96293b8 feat: P2Pool log watcher
a0b5bd9 (origin/feature/p2pool-stdin) feat: Hook in P2Pool log watcher
260644c chore: Reformatted code
2fbac18 fixed: Remove broken logging reference

Interactive Rebase

The bad commit was 3 commits back…

git rebase -i 96293b8^

This will open an editor with something like:

pick a0b5bd9 feat: Hook in P2Pool log watcher
pick 96293b8 feat: P2Pool log watcher
pick fdc79d5 chore: ignore test_logs directory
pick b996205 chore: add sample logs

Change the offending commit (96293b8) line to:

pick a0b5bd9 feat: Hook in P2Pool log watcher
edit 96293b8 feat: P2Pool log watcher
pick fdc79d5 chore: ignore test_logs directory
pick b996205 chore: add sample logs

Then save and quit the editor.

In this example a HUGE file was accidently committed.

git rm --cached test_logs/p2pool.log
git commit --amend --no-edit
git rebase --continue

Finally, do a push to totally sync things up:

git push --force origin feature/p2pool-stdin

Now your environment should be clean.

See All Action

To see all commits on all branches:

git log --all --graph --decorate --oneline