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.

854 questions
25854
votes
105 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 do I undo those commits from the local repository?
Hamza Yerlikaya
  • 49,047
  • 44
  • 147
  • 241
11151
votes
38 answers

How do I undo 'git add' before commit?

I mistakenly added files to Git using the command: git add myfile.txt I have not yet run git commit. How do I undo this so that these changes will not be included in the commit?
oz10
  • 153,307
  • 27
  • 93
  • 128
5537
votes
27 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 tried: git reset --hard HEAD But git status claims I have modified files: On branch master Changes to be committed: (use "git reset HEAD ..." to unstage) …
hap497
  • 154,439
  • 43
  • 83
  • 99
4816
votes
35 answers

Undo a Git merge that hasn't been pushed yet

I accidentally ran git merge some_other_branch on my local master branch. I haven't pushed the changes to origin master. How do I undo the merge? After merging, git status says: # On branch master # Your branch is ahead of 'origin/master' by 5…
Matt Huggins
  • 81,398
  • 36
  • 149
  • 218
4207
votes
19 answers

Undoing a git rebase

How do I easily undo a git rebase? A lengthy manual method is: checkout the commit parent to both of the branches create and checkout a temporary branch cherry-pick all commits by hand reset the faulty rebased branch to point to the temporary…
webmat
  • 58,466
  • 12
  • 54
  • 59
2023
votes
15 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
  • 161,647
  • 65
  • 194
  • 231
1943
votes
13 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
  • 22,575
  • 8
  • 27
  • 25
1864
votes
13 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
  • 106,591
  • 44
  • 118
  • 155
1354
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
  • 13,881
  • 3
  • 18
  • 9
1247
votes
16 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
  • 24,863
  • 33
  • 100
  • 188
814
votes
14 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
  • 10,503
  • 7
  • 27
  • 30
725
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
  • 261,858
  • 191
  • 397
  • 503
315
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,469
  • 3
  • 17
  • 17
204
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
  • 49,047
  • 44
  • 147
  • 241
203
votes
8 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
  • 61,194
  • 76
  • 188
  • 305
1
2 3
56 57