Git Advanced Learning:

#Navigate the commit tree

Tree-ish architecture

SHA-1 hash

HEAD pointer reference

.git/HEAD

.git/refs/heads/master

Branch reference
Tag reference
Ancestry

Some common commands:

git log

git show commit_hash

Reference to a commit

Ancestry(parents):

commit_hash^

HEAD^

master^

HEAD~ or HEAD~1

git show HEAD^

Ancestry(Grandparents):

commit_hash^^

HEAD^^

master^^

HEAD~2

git show HEAD^^


Ancestry(Great grandparents):

commit_hash^^^

HEAD^^^

master^^^

HEAD~2

git show HEAD^^^

Tree


git ls-tree HEAD

git ls-tree HEAD^

git ls-tree HEAD assets

git ls-tree HEAD assets/

git log -3

git log –since=2019-01-01

git log –until=2019-01-01

git log –after=2.weeks –before =3.days

git log –author=”Zaki”

git log –grep=”Initial”

git log –grep=”bug”

git log commit_hash…HEAD

git log SHA..SHA

git log explorers.html

Format the commit log:

git log -p

git log –stat

git log –format=medium
git log –format=short

git log –format=oneline

git log –oneline

git log –graph

git log –graph –all –oneline –decorate

Create branch:

git branch new_feature

git branch

cat .git/HEAD
output: ref:refs/heads/master

ls -la .git/refs/heads

cat .git/refs/heads/master

cat .git/refs/heads/new_feature

Switch branches:


pwd
git branch
git checkout new_feature
git branch
cat .git/HEAD
output: ref: refs/heads/new_feature

git status

git commit -am “Modifies title of index.html”
-a for all changes in directory, m for messages

git log –oneline

git help log

git checkout master

git branch shorten_title

git checkout -b shorten_title

Without commiting you can not switch to another branch. There will be conflict.

Then thre options:

  1. Commit the changes to the current branch
  2. Remove the changes checkout the file again
  3. Stash the changes

Compare branches:

git diff master..new_feature
git diff new_feature..shorten_title
git diff shorten_title..new_feature

git branch

git checkout new_feature

git branch –merged

git branch –no-merged

Change branch name:

git help branch

git branch -m seo_title

Delete branches

git branch -d branch_to_delete (From other branch)

git branch -D delete_hobe

Reset Types

To move HEAD to a specific commit
Make the project look like it did back then
Types: Soft, Mixed, Hard
Soft: git reset –soft <tree-ish>
Mixed: git reset –mixed <tree-ish>
Hard: git reset –hard <tree-ish>

tree-ish= SHA/branch name
Rollback.

If we do that previous commit will be discarded

git checkout -b reset_branch shorten_title

git reset –soft HEAD^
git log –oneline -3
git status

git commit -m “Edit again”
git log –oneline -3
git show HASH

git reset –mixed HEAD^

git status

Git Merge
One branch to another

git branch
git checkout main
git diff main..seo_title

git branch –merged
git merge seo_title

always run merge with clean working directory

git log –graph –all –oneline –decorate

Strategies to reduce conflicts:

Keep lines short
Keep commits small and focused
Beware stray edits to whitespace (spaces, tabs, line returns)
Merge often

master:
text

Stash
git stash list
git stash show -p [email protected]{0}

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published.