Git reset: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Git =Use Cases= * Git_Problems#Local_and_Remote_Origin_Branches_Have_Diverged_without_Activity_on_Local_Branch|Local and remote origin branc...")
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Internal=
=Internal=


* [[git#Commands|Git]]
* [[Git_Commands#Local_Repository_Manipulation|Git Commands]]


=Use Cases=
=Overview=


* [[Git_Problems#Local_and_Remote_Origin_Branches_Have_Diverged_without_Activity_on_Local_Branch|Local and remote origin branches have diverged without activity on the local branch]].
<tt>git reset</tt> resets the current working state to the last commit, or the specified commit.
 
git reset ''file-name''
 
=Discard All Local Changes=
 
git reset --hard HEAD
 
Resets the index and the working tree to the specified commit, by discarding all local changes to the tracked files.
 
=<span id='Use_Cases'></span>Other Use Cases=
==Local and remote origin branches have diverged without activity on the local branch==
 
{{Internal|Git_Problems#Local_and_Remote_Origin_Branches_Have_Diverged_without_Activity_on_Local_Branch|Local and remote origin branches have diverged without activity on the local branch}}
 
==Resync the Feature Branch with the State of its Tracking Branch==
 
git reset --hard origin/<''feature-branch''>
git reset --hard origin/task/test
 
==Drop Commits from the Local Feature Branch==
 
This may be necessary if an unwanted merge has been performed, and we want to get rid of it (in the example below, we get rid of exactly one commit, which is the HEAD of the branch):
 
git reset --hard HEAD~1
git push --force

Revision as of 23:39, 9 October 2019

Internal

Overview

git reset resets the current working state to the last commit, or the specified commit.

git reset file-name

Discard All Local Changes

git reset --hard HEAD

Resets the index and the working tree to the specified commit, by discarding all local changes to the tracked files.

Other Use Cases

Local and remote origin branches have diverged without activity on the local branch

Local and remote origin branches have diverged without activity on the local branch

Resync the Feature Branch with the State of its Tracking Branch

git reset --hard origin/<feature-branch>
git reset --hard origin/task/test

Drop Commits from the Local Feature Branch

This may be necessary if an unwanted merge has been performed, and we want to get rid of it (in the example below, we get rid of exactly one commit, which is the HEAD of the branch):

git reset --hard HEAD~1
git push --force