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 @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).

其他提示

Go to the folder you want to revert and do this:

git checkout -- .

See more in this answer: https://stackoverflow.com/a/16589534/207661

When I was a git novice (and afraid of the terminal) I found the easiest way was to:

  • switch to the branch you want to revert your specific subdirectory to
  • copy the subdirectory you want to revert to your desktop
  • switch back to your branch
  • overwrite the subdirectory you want to replace in your git directory with the one you copied to your desktop

If you want to do recursively from a specific directory:

git checkout -- ./*
git checkout -- mydir/*
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top