Skip to main content

Git Tutorial

Steps To Configure new folder git setup :
 
git init
git config --global user.name "USERNAME"
git config --global user.email "GITMAILID"
git remote add origin https://github.com/Dharmend/multisite.git
git config core.filemode false

Git Checkout performs the three types of operations :
 
1 – Checkout files , ( git chekout aa.txt )
2 – Checkout branch , ( git checkout “branch name” )
3 – Checkout commits , ( git checkout k9s7hjkh76 )

git diff :  
 Command : git diff
To show the difference between last commit file and current change file,if
you add file in staging area then it will not show the diff, to see
the diff use git diff --cached
git checkout vs git revert vs git reset : 

   git checkout -

  download the updated code of the branch and file while HEAD is 
  not changed While git reset, moves both the HEAD and branch refs to the specified commit

git revert-

The git revert command is a forward-moving undo operation that offers a safe method of undoing changes. Instead of deleting or orphaning commits in the commit history, a revert will create a new commit that inverses the changes specified. Git revert is a safer alternative to git reset in regards to losing work requires the id of the commit you want to remove keeping it into your history

   git reset- 

The git reset command is a complex and versatile tool for undoing changes.
It has three primary forms of invocation. These forms correspond to a command
line arguments --soft, --mixed, --hard.

  • --requires the commit you want to keep, and will consequentially remove anything after that from history.

  1. --hard : 

This is the most direct, DANGEROUS, and frequently used option. When passed --hard The Commit History ref pointers are updated to the specified commit. Then, the Staging Index and Working Directory are reset to match that of the specified commit. Any previously pending changes to the Staging Index and the Working Directory gets reset to match the state of the Commit Tree. This means any pending work that was hanging out in the Staging Index and Working Directory will be lost.

     2. --mixed : 

This is the default operating mode. The ref pointers are updated. The Staging Index is reset to the state of the specified commit. Any changes that have been undone from the Staging Index are moved to the Working Directory.

The Staging Index has been reset and the pending changes have been moved into the Working Directory. Compare this to the --hard reset case where the Staging Index was reset and the Working Directory was reset as well, losing these updates.


To be even more clear, with a log like this:

# git log --oneline

cb76ee4 wrong
01b56c6 test
2e407ce first commit
Using git revert cb76ee4 will by default bring your files back to 01b56c6 and will 
add a further commit to your history:

8d4406b Revert "wrong"
cb76ee4 wrong
01b56c6 test
2e407ce first commit
git reset 01b56c6 will instead bring your files back to 01b56c6 and will clean 
up any other commit after that from your history :

01b56c6 test
2e407ce first commit
Head Reset : 
git checkout hotfix
git reset HEAD~2
I means  the hotfix branch revert back to two heads or two commits,

 Git Stash :  

git stash 
git stash list
git stash apply 2  == {it will apply the 2nd stash}

Comments

Popular posts from this blog

Get The field values of node in Drupal 8

use Drupal \ node \ NodeInterface ; /** * Implements hook_ENTITY_TYPE_insert() for node entities. * * This tests saving a node on node insert. * * @see \Drupal\node\Tests\NodeSaveTest::testNodeSaveOnInsert() */ function node_test_node_insert ( NodeInterface $node ) { // Set the node title to the node ID and save. if ( $node - > getTitle ( ) == 'new' ) { $node - > setTitle ( 'Node ' . $node - > id ( ) ) ; $node - > setNewRevision ( FALSE ) ; $node - > save ( ) ; } } Now There is so many functions are there to get the values, For All the functions available visit the API code, https://api.drupal.org/api/drupal/core%21modules%21node%21src%21NodeInterface.php/interface/NodeInterface/8.2.x Some of as below, Node edit form, Drupal 8 Automatically Load the whole object no need to load the entity like below, if ($event->getFormId() == 'node_alexa_audio_clips_edit_form') { $node = \Drupal::ro...

Drupal Setup with docker

Option 1:  docker pull mysql docker pull phpmyadmin docker pull drupal docker run -d --name MysqlClient -e MYSQL_ROOT_PASSWORD=drupal mysql Download the phpmyadmin image and Setup Container: docker run --name phpmyadmin -d --link MysqlClient:db -p 8083:80 phpmyadmin Download the Drupal image and Setup Container: docker run -d --name dweb2 --link MysqlClient -p 8082:80 -e MYSQL_USER:root -e MYSQL_PASSWORD:drupal drupal   We are using docker4 drupal and following below URL https://wodby.com/docs/1.0/stacks/drupal/local/ From Mount my codebase Download and unpack docker4drupal.tar.gz with hidden files in a new directory, also get the drupal code with in web directory composer create - project drupal / recommended - project my_site_name_dir It means with in new directory we have docker files and drupal files also has web folder for drupal. now run docker-compose up -d Now PROJECT_BASE_URL is mentioned in .env file open this url in the web with port, it will open the drupal page, ...