SlideShare une entreprise Scribd logo
1  sur  2
Shobhakar’s Blog #1 for Git Revert 1
Shobhakar’s Blog #1 for Git
Revert
PROBLEM STATEMENT: Suppose you are working in a tech company where you
may encounter two situations:
1. Working in a Team with Shared Branches:
If you are working in a team where code is regularly pushed to shared
branches, and you need to revert any accidentally pushed code while
maintaining the revert history.
Let's discuss the first situation.
Important Points
1. Push a new commit that reverts the pushed commit.
2. This strategy is suitable for public or shared branches where multiple
developers are pushing their changes.
Commands:
Git revert HEAD
Git push origin main
2. Working on a Private Branch:
If you are working on your private branch, committing daily, and accidentally
pushing code that needs to be reverted without maintaining the history in the
Git repository.
Important Points
1. Delete the pushed commit.
2. This strategy is suitable for private branches that are not dependent on other
team members.
Commands:
Shobhakar’s Blog #1 for Git Revert 2
1. Unstage the pushed commit.
Command: git reset Head~1
2. Discard the changes and move the branch pointer.
Command: git reset --hard HEAD~1
3. Force push to update the remote repository.
Command: git push -f origin main
1. Understanding the Differences and When to Use Each Method:
In both scenarios, the goal is to revert a code commit. However, the context
significantly changes the way you should go about it.
When working on shared branches, the changes you push could affect other
developers. Therefore, pushing a new commit to revert the previous one
ensures that everyone can see what has happened and adjust their work
accordingly. This preserves the history and avoids confusion.
On the other hand, when working on a private branch, you have more
flexibility. You can delete the pushed commit and force push the branch. This
erases the mistake from the history as if it never happened, which is generally
a cleaner approach when the changes aren't impacting others.
Remember, using git push -f (force push) should be done cautiously. It can
potentially overwrite changes pushed by others, which can lead to data loss.
Always ensure you're on a private branch when using it.

Contenu connexe

Similaire à Application of Git Revert in different situation

Checkitmobile - using Git for development
Checkitmobile - using Git for developmentCheckitmobile - using Git for development
Checkitmobile - using Git for development
Gerrit Wanderer
 
Checkitmobile advanced git
Checkitmobile advanced gitCheckitmobile advanced git
Checkitmobile advanced git
Gerrit Wanderer
 
Git Basics walkthough to all basic concept and commands of git
Git Basics walkthough to all basic concept and commands of gitGit Basics walkthough to all basic concept and commands of git
Git Basics walkthough to all basic concept and commands of git
DivyanshGupta922023
 

Similaire à Application of Git Revert in different situation (20)

Git Series. Episode 3. Git Flow and Github-Flow
Git Series. Episode 3. Git Flow and Github-FlowGit Series. Episode 3. Git Flow and Github-Flow
Git Series. Episode 3. Git Flow and Github-Flow
 
Managing releases effectively through git
Managing releases effectively through gitManaging releases effectively through git
Managing releases effectively through git
 
Introduction to Git (part 2)
Introduction to Git (part 2)Introduction to Git (part 2)
Introduction to Git (part 2)
 
Gn unify git
Gn unify gitGn unify git
Gn unify git
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Checkitmobile - using Git for development
Checkitmobile - using Git for developmentCheckitmobile - using Git for development
Checkitmobile - using Git for development
 
Git workshop
Git workshopGit workshop
Git workshop
 
Checkitmobile advanced git
Checkitmobile advanced gitCheckitmobile advanced git
Checkitmobile advanced git
 
Git essentials
Git essentialsGit essentials
Git essentials
 
Vincit Teatime 2015.2 - Otto Kekäläinen: Don't be a git
Vincit Teatime 2015.2 - Otto Kekäläinen: Don't be a gitVincit Teatime 2015.2 - Otto Kekäläinen: Don't be a git
Vincit Teatime 2015.2 - Otto Kekäläinen: Don't be a git
 
Git & Code review
Git & Code reviewGit & Code review
Git & Code review
 
Git Primer
Git PrimerGit Primer
Git Primer
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshell
 
Git for standalone use
Git for standalone useGit for standalone use
Git for standalone use
 
01 git interview questions & answers
01   git interview questions & answers01   git interview questions & answers
01 git interview questions & answers
 
Git Basics
Git BasicsGit Basics
Git Basics
 
Git learning
Git learningGit learning
Git learning
 
Github
GithubGithub
Github
 
Git Basics walkthough to all basic concept and commands of git
Git Basics walkthough to all basic concept and commands of gitGit Basics walkthough to all basic concept and commands of git
Git Basics walkthough to all basic concept and commands of git
 
GIT_Overview.
GIT_Overview.GIT_Overview.
GIT_Overview.
 

Dernier

☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...
☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...
☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...
mikehavy0
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx
rahulmanepalli02
 

Dernier (20)

Signal Processing and Linear System Analysis
Signal Processing and Linear System AnalysisSignal Processing and Linear System Analysis
Signal Processing and Linear System Analysis
 
What is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsWhat is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, Functions
 
Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...
 
Passive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.pptPassive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.ppt
 
Worksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptxWorksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptx
 
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...
☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...
☎️Looking for Abortion Pills? Contact +27791653574.. 💊💊Available in Gaborone ...
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx
 
analog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxanalog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptx
 
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdflitvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
 
Databricks Generative AI FoundationCertified.pdf
Databricks Generative AI FoundationCertified.pdfDatabricks Generative AI FoundationCertified.pdf
Databricks Generative AI FoundationCertified.pdf
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptx
 
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptx
 
Introduction-to- Metrology and Quality.pptx
Introduction-to- Metrology and Quality.pptxIntroduction-to- Metrology and Quality.pptx
Introduction-to- Metrology and Quality.pptx
 
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and ToolsMaximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
 
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdfInstruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
 
Working Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdfWorking Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdf
 
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
 

Application of Git Revert in different situation

  • 1. Shobhakar’s Blog #1 for Git Revert 1 Shobhakar’s Blog #1 for Git Revert PROBLEM STATEMENT: Suppose you are working in a tech company where you may encounter two situations: 1. Working in a Team with Shared Branches: If you are working in a team where code is regularly pushed to shared branches, and you need to revert any accidentally pushed code while maintaining the revert history. Let's discuss the first situation. Important Points 1. Push a new commit that reverts the pushed commit. 2. This strategy is suitable for public or shared branches where multiple developers are pushing their changes. Commands: Git revert HEAD Git push origin main 2. Working on a Private Branch: If you are working on your private branch, committing daily, and accidentally pushing code that needs to be reverted without maintaining the history in the Git repository. Important Points 1. Delete the pushed commit. 2. This strategy is suitable for private branches that are not dependent on other team members. Commands:
  • 2. Shobhakar’s Blog #1 for Git Revert 2 1. Unstage the pushed commit. Command: git reset Head~1 2. Discard the changes and move the branch pointer. Command: git reset --hard HEAD~1 3. Force push to update the remote repository. Command: git push -f origin main 1. Understanding the Differences and When to Use Each Method: In both scenarios, the goal is to revert a code commit. However, the context significantly changes the way you should go about it. When working on shared branches, the changes you push could affect other developers. Therefore, pushing a new commit to revert the previous one ensures that everyone can see what has happened and adjust their work accordingly. This preserves the history and avoids confusion. On the other hand, when working on a private branch, you have more flexibility. You can delete the pushed commit and force push the branch. This erases the mistake from the history as if it never happened, which is generally a cleaner approach when the changes aren't impacting others. Remember, using git push -f (force push) should be done cautiously. It can potentially overwrite changes pushed by others, which can lead to data loss. Always ensure you're on a private branch when using it.