Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git "revert" current directory

In svn it's possible to do svn revert ./* in which the current directory and ONLY the current directory gets reverted.

What is the git equivalent to svn revert in which only the current directory gets reverted?

I know that there's git reset --hard, but it reverts everything and not just the current directory.

How would I revert just the current directory in git?

like image 780
pillarOfLight Avatar asked Jan 02 '13 16:01

pillarOfLight


People also ask

How do I revert a folder in git?

How would I revert just the current directory in Git? Use git checkout instead of reset. git checkout <branchname>~1 -- path/to/directory/you/want/updated should do the trick. The ~1 after the branch name means back one commit.

How do I revert my current commit?

The easiest way to undo the last Git commit is to execute the “git reset” command with the “–soft” option that will preserve changes done to your files. You have to specify the commit to undo which is “HEAD~1” in this case. The last commit will be removed from your Git history.

How do I revert changes in git?

First, you'll need to find the ID of the revision you want to see. This assumes that you're developing on the default main branch. Once you're back in the main branch, you can use either git revert or git reset to undo any undesired changes.

How do I get rid of all changes in working directory?

There are two Git commands a developer must use in order to discard all local changes in Git, remove all uncommited changes and revert their Git working tree back to the state it was in when the last commit took place. The commands to discard all local changes in Git are: git reset –hard. git clean -fxd.


1 Answers

Like @vcsjones says, the solution here is git checkout:

git checkout <refspec> -- path/to/directory  # or path/to/file 

where <refspec> can, for instance, be HEAD, that is, the current working commit. Note that this usage of the checkout command will affect the working tree BUT NOT THE INDEX.

git revert is used to "revert a commit", and by this, it should NOT be understood that the commit disappears from the tree (it would play havoc with history -- if you want that, look at git rebase -i). A reverted commit consists of applying, in reverse, all changes from the commit given as an argument to the tree and create a new commit with the changes (with a default commit message, which you can modify).

like image 72
fge Avatar answered Sep 29 '22 21:09

fge