SlideShare uma empresa Scribd logo
1 de 10
git Most Used Commands
GIT Commands
Commands Description
git --version To check version of Git installed.
git config--system user.name <username> System level (All users on the system)
git config --global user.name <username> Global level (for all the projects of a user)
git config --local user.name <username> Local (default and specific for a repository)
git config --global core.excludesfile
%USERPROFILE%.gitignore
. gitignore files should have the list of files to be
ignored.
git add . To add new and modified but not deleted.
git add -u To add modified and deleted but not new
files/directories
GIT Commands
Commands Description
git Add -u To add modified and deleted and new
files/directories.
git commit --am “<message to commit> Creates a commit and adds files to staging.
git commit --m “<message to commit> Creates a commit from staging. Assumes files already
added to staging
git init Creates .git subfolder in the project, which contains all
necessary metadata
git remote add origin
https://github.com/Viyaan/<repository>.git
To add a new repo
git push origin <source_branch>:<destination branch> Actual syntax but the below syntax is enough
git push -u origin <source branch name> push your changes to selected branch, since source
and destination will always be same. It’s enough to
mention only source branch.
GIT Commands
Commands Description
git status gives status of tracked and untracked changes in your
local repository.
git branch list all available branches in local system.
git branch -r list all branches in repository
git branch <new branch name> create a new branch
git checkout <branch name> switch to another branch
git checkout -b <branch name> creates and switches to another branch
git merge <branch name> Merges specified branch into current.
GIT Commands
Commands Description
git rm <file name> To delete a file, you must commit and push after
deleting.
git diff <file-name> To see difference between uncommitted version to
remote version of a file.
git diff shows the changes you have done in your existing file
(compare different versions of your files)
git log Prints log of past commits
git log --oneline Prints log of past commits in one line.
git tag list all tags.
git tag <tag name> create a tag. You need to push after new tag is
created.
GIT Commands
Commands Description
git branch -D <branch name> To delete a branch. You must push after delete
command.
git branch -d <branch name> Same as above but this time it will ask for
confirmation If its not merged.
git push origin :<destination branch> After deleting you must push and while pushing you
should mention the destination branch. Destination
branch is the branch u deleted.
git tag -d <tag name> To delete a tag, use small d and not capital.
git clone <clone url> To clone a repository
git fetch origin To fetch new data from remote repository. But it
doesn’t integrate any of those new data into your
working files.
GIT Commands
Commands Description
git pull pull not only downloads new data; it also
directly integrates it into your current working copy
files.
git remote add <remote-name> <remote-url> To add a new remote, use the git remote
add command on the terminal, in the directory your
repository is stored at.
git remote show To see number of remote repositories available.
git stash Git stash temporarily shelves or stashes changes made
to your working copy so you can work on something
else, and come back and re-apply them later.
git stash save <stash name> To save list of uncommitted changes in stash.
git stash list List of stashes.
git stash pop Apply changes which were stashed.
GIT Commands
Commands Description
git commit --amend Modify the most recent commit
git commit --amend -m "an updated commit message" Modify the most recent commit message
git rev -parse HEAD Specify where head pointing too.
Reset
• git reset --soft <commit id>
• git reset --mixed <commit id>
• The difference between --mixed and --soft is whether or not your index is also modified. So, if we're on branch master
with this series of commits:
• - A - B - C (master)
• HEADpoints to C and the index matches C.
• When we run git reset --soft B, master (and thus HEAD) now points to B, but the index still has the changes from C; git
status will show them as staged. So if we run git commit at this point, we'll get a new commit with the same changes as C.
• ________________________________________
• Okay, so starting from here again:
• - A - B - C (master)
• Now let's do git reset --mixed B. (Note: --mixed is the default option). Once again, master and HEAD point to B, but this
time the index is also modified to match B. If we run git commit at this point, nothing will happen since the index matches
HEAD. We still have the changes in the working directory, but since they're not in the index, git status shows them as
unstaged. To commit them, you would git add and then commit as usual.
• ________________________________________
• And finally, --hard is the same as --mixed (it changes your HEAD and index), except that --hard also modifies your
working directory. If we're at C and run git reset --hard B, then the changes added in C, as well as any uncommitted
changes you have, will be removed, and the files in your working copy will match commit B. Since you can permanently
lose changes this way, you should always run git status before doing a hard reset to make sure your working directory is
clean or that you're okay with losing your uncommitted changes.
Reset
• git reset --hard <commit id>
resets the HEAD to any commit mentioned in command. And throws away all
your changes which is made after the commit corresponding to the commit id.

Mais conteúdo relacionado

Mais procurados (20)

Github basics
Github basicsGithub basics
Github basics
 
Git Introduction
Git IntroductionGit Introduction
Git Introduction
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
 
Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
 
Git training v10
Git training v10Git training v10
Git training v10
 
Basic Git Intro
Basic Git IntroBasic Git Intro
Basic Git Intro
 
Intro to Git and GitHub
Intro to Git and GitHubIntro to Git and GitHub
Intro to Git and GitHub
 
Git and git flow
Git and git flowGit and git flow
Git and git flow
 
Git and Github Session
Git and Github SessionGit and Github Session
Git and Github Session
 
GIT presentation
GIT presentationGIT presentation
GIT presentation
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
 
git and github
git and githubgit and github
git and github
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Introduction To Git
Introduction To GitIntroduction To Git
Introduction To Git
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
 

Semelhante a Git commands

Atlassian git cheatsheet
Atlassian git cheatsheetAtlassian git cheatsheet
Atlassian git cheatsheetAbdul Basit
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshopthemystic_ca
 
Introduction to git, a version control system
Introduction to git, a version control systemIntroduction to git, a version control system
Introduction to git, a version control systemKumaresh Chandra Baruri
 
Git Memento of basic commands
Git Memento of basic commandsGit Memento of basic commands
Git Memento of basic commandsZakaria Bouazza
 
Pro git - grasping it conceptually
Pro git - grasping it conceptuallyPro git - grasping it conceptually
Pro git - grasping it conceptuallyseungzzang Kim
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?9 series
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubDSC GVP
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | WorkshopAnuchit Chalothorn
 
Git cheatsheet
Git cheatsheetGit cheatsheet
Git cheatsheetsynapsefre
 
Git Intermediate Course
Git Intermediate CourseGit Intermediate Course
Git Intermediate CourseAli Abbasi
 
Git tutorial undoing changes
Git tutorial   undoing changesGit tutorial   undoing changes
Git tutorial undoing changesLearningTech
 
Git Tricks — git utilities that make life git easier
Git Tricks — git utilities that make life git easierGit Tricks — git utilities that make life git easier
Git Tricks — git utilities that make life git easierChristoph Matthies
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmdsrinathcox
 

Semelhante a Git commands (20)

Atlassian git cheatsheet
Atlassian git cheatsheetAtlassian git cheatsheet
Atlassian git cheatsheet
 
GIT Basics
GIT BasicsGIT Basics
GIT Basics
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshop
 
Introduction to git, a version control system
Introduction to git, a version control systemIntroduction to git, a version control system
Introduction to git, a version control system
 
Git Memento of basic commands
Git Memento of basic commandsGit Memento of basic commands
Git Memento of basic commands
 
Pro git - grasping it conceptually
Pro git - grasping it conceptuallyPro git - grasping it conceptually
Pro git - grasping it conceptually
 
Git github
Git githubGit github
Git github
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHub
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | Workshop
 
Git cheatsheet
Git cheatsheetGit cheatsheet
Git cheatsheet
 
Git Intermediate Course
Git Intermediate CourseGit Intermediate Course
Git Intermediate Course
 
Git basics for beginners
Git basics for beginnersGit basics for beginners
Git basics for beginners
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git commands
Git commandsGit commands
Git commands
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 
Git for beginners
Git for beginnersGit for beginners
Git for beginners
 
Git tutorial undoing changes
Git tutorial   undoing changesGit tutorial   undoing changes
Git tutorial undoing changes
 
Git Tricks — git utilities that make life git easier
Git Tricks — git utilities that make life git easierGit Tricks — git utilities that make life git easier
Git Tricks — git utilities that make life git easier
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmd
 

Mais de Viyaan Jhiingade (7)

Rate limiting
Rate limitingRate limiting
Rate limiting
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
No sql
No sqlNo sql
No sql
 
Rest Webservice
Rest WebserviceRest Webservice
Rest Webservice
 
Storm
StormStorm
Storm
 
Jenkins CI
Jenkins CIJenkins CI
Jenkins CI
 
Kafka RealTime Streaming
Kafka RealTime StreamingKafka RealTime Streaming
Kafka RealTime Streaming
 

Último

Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 

Último (20)

Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 

Git commands

  • 1. git Most Used Commands
  • 2. GIT Commands Commands Description git --version To check version of Git installed. git config--system user.name <username> System level (All users on the system) git config --global user.name <username> Global level (for all the projects of a user) git config --local user.name <username> Local (default and specific for a repository) git config --global core.excludesfile %USERPROFILE%.gitignore . gitignore files should have the list of files to be ignored. git add . To add new and modified but not deleted. git add -u To add modified and deleted but not new files/directories
  • 3. GIT Commands Commands Description git Add -u To add modified and deleted and new files/directories. git commit --am “<message to commit> Creates a commit and adds files to staging. git commit --m “<message to commit> Creates a commit from staging. Assumes files already added to staging git init Creates .git subfolder in the project, which contains all necessary metadata git remote add origin https://github.com/Viyaan/<repository>.git To add a new repo git push origin <source_branch>:<destination branch> Actual syntax but the below syntax is enough git push -u origin <source branch name> push your changes to selected branch, since source and destination will always be same. It’s enough to mention only source branch.
  • 4. GIT Commands Commands Description git status gives status of tracked and untracked changes in your local repository. git branch list all available branches in local system. git branch -r list all branches in repository git branch <new branch name> create a new branch git checkout <branch name> switch to another branch git checkout -b <branch name> creates and switches to another branch git merge <branch name> Merges specified branch into current.
  • 5. GIT Commands Commands Description git rm <file name> To delete a file, you must commit and push after deleting. git diff <file-name> To see difference between uncommitted version to remote version of a file. git diff shows the changes you have done in your existing file (compare different versions of your files) git log Prints log of past commits git log --oneline Prints log of past commits in one line. git tag list all tags. git tag <tag name> create a tag. You need to push after new tag is created.
  • 6. GIT Commands Commands Description git branch -D <branch name> To delete a branch. You must push after delete command. git branch -d <branch name> Same as above but this time it will ask for confirmation If its not merged. git push origin :<destination branch> After deleting you must push and while pushing you should mention the destination branch. Destination branch is the branch u deleted. git tag -d <tag name> To delete a tag, use small d and not capital. git clone <clone url> To clone a repository git fetch origin To fetch new data from remote repository. But it doesn’t integrate any of those new data into your working files.
  • 7. GIT Commands Commands Description git pull pull not only downloads new data; it also directly integrates it into your current working copy files. git remote add <remote-name> <remote-url> To add a new remote, use the git remote add command on the terminal, in the directory your repository is stored at. git remote show To see number of remote repositories available. git stash Git stash temporarily shelves or stashes changes made to your working copy so you can work on something else, and come back and re-apply them later. git stash save <stash name> To save list of uncommitted changes in stash. git stash list List of stashes. git stash pop Apply changes which were stashed.
  • 8. GIT Commands Commands Description git commit --amend Modify the most recent commit git commit --amend -m "an updated commit message" Modify the most recent commit message git rev -parse HEAD Specify where head pointing too.
  • 9. Reset • git reset --soft <commit id> • git reset --mixed <commit id> • The difference between --mixed and --soft is whether or not your index is also modified. So, if we're on branch master with this series of commits: • - A - B - C (master) • HEADpoints to C and the index matches C. • When we run git reset --soft B, master (and thus HEAD) now points to B, but the index still has the changes from C; git status will show them as staged. So if we run git commit at this point, we'll get a new commit with the same changes as C. • ________________________________________ • Okay, so starting from here again: • - A - B - C (master) • Now let's do git reset --mixed B. (Note: --mixed is the default option). Once again, master and HEAD point to B, but this time the index is also modified to match B. If we run git commit at this point, nothing will happen since the index matches HEAD. We still have the changes in the working directory, but since they're not in the index, git status shows them as unstaged. To commit them, you would git add and then commit as usual. • ________________________________________ • And finally, --hard is the same as --mixed (it changes your HEAD and index), except that --hard also modifies your working directory. If we're at C and run git reset --hard B, then the changes added in C, as well as any uncommitted changes you have, will be removed, and the files in your working copy will match commit B. Since you can permanently lose changes this way, you should always run git status before doing a hard reset to make sure your working directory is clean or that you're okay with losing your uncommitted changes.
  • 10. Reset • git reset --hard <commit id> resets the HEAD to any commit mentioned in command. And throws away all your changes which is made after the commit corresponding to the commit id.