Questions tagged [undo]

Undo is a command in many computer programs. It erases the last change done to the document reverting it to an older state. In some more advanced programs such as graphic processing, undo will negate the last command done to the file being edited.

793 questions
22674
votes
92 answers

How do I undo the most recent local commits in Git?

I accidentally committed the wrong files to Git, but didn't push the commit to the server yet. How can I undo those commits from the local repository?
Hamza Yerlikaya
  • 47,689
  • 37
  • 135
  • 231
4428
votes
21 answers

Reset local repository branch to be just like remote repository HEAD

How do I reset my local branch to be just like the branch on the remote repository? I did: git reset --hard HEAD But when I run a git status, On branch master Changes to be committed: (use "git reset HEAD ..." to unstage) modified: …
hap497
  • 129,793
  • 42
  • 77
  • 91
4283
votes
33 answers

Undo a Git merge that hasn't been pushed yet

Within my master branch, I did a git merge some-other-branch locally, but never pushed the changes to origin master. I didn't mean to merge, so I'd like to undo it. When doing a git status after my merge, I was getting this message: # On branch…
Matt Huggins
  • 73,807
  • 32
  • 140
  • 214
3500
votes
18 answers

Undoing a git rebase

Does anybody know how to easily undo a git rebase? The only way that comes to mind is to go at it manually: git checkout the commit parent to both of the branches then create a temp branch from there cherry-pick all commits by hand replace the…
webmat
  • 50,648
  • 12
  • 52
  • 59
1771
votes
14 answers

Undo working copy modifications of one file in Git?

After the last commit, I modified a bunch of files in my working copy, but I want to undo the changes to one of those files, as in reset it to the same state as the most recent commit. However, I only want to undo the working copy changes of just…
hasen
  • 148,751
  • 62
  • 182
  • 223
1496
votes
12 answers

How to undo "git commit --amend" done instead of "git commit"

I accidentally amended my previous commit. The commit should have been separate to keep history of the changes I made to a particular file. Is there a way to undo that last commit? If I do something like git reset --hard HEAD^, the first commit also…
Jesper Rønn-Jensen
  • 91,561
  • 40
  • 112
  • 147
1334
votes
11 answers

Can I delete a git commit but keep the changes?

In one of my development branches, I made some changes to my codebase. Before I was able to complete the features I was working on, I had to switch my current branch to master to demo some features. But just using a "git checkout master" preserved…
tanookiben
  • 16,365
  • 7
  • 24
  • 25
1082
votes
8 answers

How to uncommit my last commit in Git

How can I uncommit my last commit in git? Is it git reset --hard HEAD or git reset --hard HEAD^ ?
richard
  • 11,153
  • 3
  • 16
  • 9
964
votes
14 answers

git undo all uncommitted or unsaved changes

I'm trying to undo all changes since my last commit. I tried git reset --hard and git reset --hard HEAD after viewing this post. I responds with head is now at 18c3773... but when I look at my local source all the files are still there. What am I…
Antarr Byrd
  • 20,852
  • 26
  • 85
  • 154
709
votes
10 answers

How do I do redo (i.e. "undo undo") in Vim?

In Vim, I did too much undo. How do I undo this (that is, redo)?
flybywire
  • 232,954
  • 184
  • 384
  • 491
586
votes
10 answers

How do I "un-revert" a reverted Git commit?

Given a change that has been committed using commit, and then reverted using revert, what is the best way to then undo that revert? Ideally, this should be done with a new commit, so as to not re-write history.
JimmidyJoo
  • 7,935
  • 6
  • 23
  • 27
272
votes
8 answers

How to undo a git pull?

I would like to undo my git pull on account of unwanted commits on the remote origin, but I don't know to which revision I have to reset back to. How can I just go back to the state before I did the git pull on the remote origin?
Kartins
  • 3,019
  • 2
  • 15
  • 17
190
votes
6 answers

Git undo changes in some files

While coding I added print statements into some files to keep track of what was going on. When I am done, is it possible to revert changes in some files, but commit the file I actually worked on? Say I added print in file A, but I modified file B.…
Hamza Yerlikaya
  • 47,689
  • 37
  • 135
  • 231
165
votes
7 answers

Undo git update-index --skip-worktree

A while ago I did this to ignore changes to a file tracked by git: git update-index --skip-worktree Now I actually want to commit changes to that file to source. How do I undo the effects of skip-worktree?
Kevin Burke
  • 49,451
  • 66
  • 163
  • 280
145
votes
9 answers

Undo git mv (rename)

What is the right way to undo a rename in git, like: git mv file1 file2
jrdioko
  • 28,317
  • 26
  • 75
  • 116
1
2 3
52 53