Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
git-tutorial
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michael Alan Marsh
git-tutorial
Commits
99428c14
Commit
99428c14
authored
7 years ago
by
Daniel McVicker
Browse files
Options
Downloads
Patches
Plain Diff
Added 'undoing changes' section
parent
5ca789d6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
README
+32
-0
32 additions, 0 deletions
README
with
32 additions
and
0 deletions
README
+
32
−
0
View file @
99428c14
...
...
@@ -706,6 +706,38 @@ dealing with conflicts
Save the log message file, and exit. We now have completed our merge! See what
the log shows.
undoing changes
---------------
When things stop working, sometimes starting over is easier than trying to
find and fix the error. One of the nice features of git is that you can
"go back" to any of your commits. For example, if you want to reset your
repository to the state it was in when you last committed, run:
git reset --hard HEAD
More generally, you can restore your local repository to ANY previous commit.
To do this, find the commit hash of the commit you want to restore (e.g. via
git log) and run:
git reset --hard <hash>
However, since this discards changes to all files in the repository, it's not
ideal if only one or two files are broken, and the rest have changes you
want to keep. Fortunately, git has a way to restore individual files. To
reset file1, run:
git checkout [<commit hash>] -- file1
(Note: the 'commit hash' argument is optional. If you omit it, git will
default to using the previous commit)
IMPORTANT: The ability to restore old versions can be incredibly useful,
but only if you make regular commits. There WILL be a time when you'll need
to reset your repository -- if your last working commit was five minutes
ago, this will be a minor setback; if it was five hours ago, you'll be much
less happy. Remember: commit early, commit often!
gitk
----
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment