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

How to span column of custom table in Drupal

If you want to span the column of custom drupal table like below image, Follow the below code to make the header of the table , <?php $header = array('S.N','District', array('data' => '<div class ="house">Household </div><br><span>Rural</span> <p>Urban</p>','colspan' => 2), array('data' => '<div class ="house">Members</div> <br><span>Rural</span> <p>Urban</p>','colspan' => 2), 'Duplicate/Failed Registration', array('data' => '<div class ="house">Pending De duplication </div><br><span>Rural</span> <p>Urban</p>','colspan' => 2), 'Non Un-organised Workers', 'SSID Generated', 'No. of Card Personlised', ); $rows[] = arra...

Drupal 8 : Link actions,Link menus,Link Tasks,Routings

Drupal 8 : Link actions,Link menus,Link Tasks,Routings Link actions Local actions have also been moved out of the hook_menu() system in Drupal 8 .Use actions to define local operations such as adding new items to an administrative list (menus, contact categories, etc). Local actions are defined in a YAML format, named after the module they are defined by. Such as menu_ui.links.action.yml for this example from menu_ui module: menu_ui.link_add:   route_name: menu_ui.link_add   title: 'Add link'   appears_on:     - menu_ui.menu_edit Here, menu_ui.link_add: It is the Unique name of the link action Most likely start with module name, route_name : Name of the route it means when click the link it redirect to this route, appears_on :  An array of route names for this action to be display on. Now how to know the Route name of any internal/external admin pages like below, By through the drupal console we achieve it, drupal debug:router...

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...