Git

Git - How To

use reset soft mixed hard

Reset, restore and revert There are three commands with similar names: git reset, git restore and git revert. • git-revert(1) is about making a new commit that reverts the changes made by other commits. • git-restore(1) is about restoring files in the working tree from either the index or another commit. This command does not update your branch. The command can also be used to restore files in the index from another commit. • git-reset(1) is about updating your branch, moving the tip in order to add or remove commits from the branch. This operation changes the commit history. git reset can also be used to restore the index, overlapping with git restore.

Conclusion, it’s still too difficult to understand git reset, hmm, just stay away from git reset.

If I want to change branch, uses git rebase with fixup or squash.

rebase with fixing conflicts by always using a branch

Git - Explanation

understanding git log

  1. commit object filename/hash 5a761fe actually sits in .git/objects/5a/761
  2. index a871d21e..00000000 means file hash before commit..file hash after commit
commit 5a761fe301ebfe45e0a72d99e619102cba149e6d (HEAD -> ON-1987-tiger-test-remove-aws-credentials, origin/ON-1987-tiger-test-remove-aws-credentials) 
Author: ynotstartups <[email protected]>
Date:   Tue Aug 8 18:15:54 2023 +0100

    remove not needed configure_aws.sh

    The following environment variables are provided in github action
    aws-actions/configure-aws-credentials@v2 used in docker-compose-dev.yml

diff --git a/.github/configure_aws.sh b/.github/configure_aws.sh
deleted file mode 100644
index a871d21e..00000000
--- a/.github/configure_aws.sh
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/sh
-set -eu
-
-export_aws_credentials () {
-   awsProfile=${AWS_PROFILE:-default}
-   AWS_ACCESS_KEY_ID=$(aws --profile "$awsProfile" configure get aws_access_key_id)
-   AWS_SECRET_ACCESS_KEY=$(aws --profile "$awsProfile" configure get aws_secret_access_key)
-   AWS_SESSION_TOKEN=$(aws --profile "$awsProfile" configure get aws_session_token)
-   export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN
-
-}
-
-export_aws_credentials

checkout replaced by switch and restore

Since git version 2.23.0, see changelog, all functionalities of git checkout is replaced by git restore and git switch, make git checkout obsolete.

Two new commands “git switch” and “git restore” are introduced to split “checking out a branch to work on advancing its history” and “checking out paths out of the index and/or a tree-ish to work on advancing the current history” out of the single “git checkout” command.

for example,

git checkout <commit> is replaced by git switch for

git checkout [commit] <paths> is replaced by git restore

.. vs ...

To see the code diff in feature branch?

git diff master...feature

To see the commits added in feature branch?

git log master..feature

Explanation for git diff

Use the three dots like this git diff [<options>] <commit>...<commit>.

  B---C---D master (Branch)
 /
A
 \
  H---I feature (Branch)

Two dots - show the diffs between all changes on both sides, use the git diff master..feature, output: (diff of H, I against B, C, D)

Three dots - to show the diffs between the last common ancestor (A), aka the commit we started the feature branch, use git diff master...feature, output: (diff of H, I against A).

Note that … and .. don’t have the same meaning in git log

However, “diff” is about comparing two endpoints, not ranges, and the range notations (“..” and “”) do not mean a range as defined in the “SPECIFYING RANGES” section in gitrevisions[7].

from git diff --help

Explanation for git log

Kind of like reversing the meaning for ... and .. in git diff

git log master..feature

# equivalent to

git log ^master feature

# refers to commit `H and I`
git log master...feature

# equivalent to

git log master feature --not $(git merge-base --all master feature)

# refers to commit `B, C,D, H and I`

See man gitrevision under SPECIFYING RANGES section

See also

The best stack overflow explanation see here