撤消 git mv(重命名)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4902795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Undo git mv (rename)
提问by jrdioko
What is the right way to undo a rename in git, like:
在 git 中撤消重命名的正确方法是什么,例如:
git mv file1 file2
回答by CanSpice
Non-cheeky answer:
不客气的回答:
git mv file2 file1
回答by Klas Mellbourn
If you have done no other changes (that you want to keep) since the last commit, you can do
如果自上次提交以来您没有进行其他更改(您想保留),则可以执行
git reset --hard
回答by zbig
git reset HEAD file2
did the trick for me
对我有用
回答by zedd45
In my case, I moved an entire folder, then realized I should not have.
就我而言,我移动了整个文件夹,然后意识到我不应该这样做。
I really liked @Dave Konopka's answer, but I did not have much success with that approach (maybe my version of GIT (1.8.4)? My files still showed as deleted. I had other changes on the stack that I did not want to lose (unfortunately).
我真的很喜欢@Dave Konopka 的回答,但我用这种方法并没有取得太大的成功(也许是我的 GIT 版本(1.8.4)?我的文件仍然显示为已删除。我不想在堆栈上进行其他更改输(不幸)。
I did have success doing this:
我确实成功做到了这一点:
git reset moved_folder
git checkout original_folder
回答by William Pursell
It depends on what you want to accomplish. If you want it to appear as if the file was never moved, then you can reset (or rebase) back to before the move. If you don't care about the history, then just move it back.
这取决于你想完成什么。如果您希望它看起来好像文件从未移动过,那么您可以重置(或变基)回到移动之前。如果你不关心历史,那就把它移回去。
回答by Dave Konopka
If you've accidentally renamed a large number of files and want to get back to where you started, delete all the renamed files that show up as adds
under a git status
call.
如果您不小心重命名了大量文件并想回到开始的位置,请删除显示adds
在git status
通话中的所有重命名文件。
Once you delete all the changed files you can run git checkout -- *
to get back the original file names locally.
删除所有更改的文件后,您可以运行git checkout -- *
以在本地取回原始文件名。
回答by Kamaraju Kusumanchi
git reset HEAD file2
git checkout -- file1
rm file2
The first command unstages file2 but leaves a copy of it around. The second command restores the original file and the third deletes the new file.
第一个命令取消暂存 file2 但留下它的副本。第二个命令恢复原始文件,第三个命令删除新文件。
回答by sevencontinents
The trick I used was to do a git stash to undo all my changes (which includes restoring the mv'd files) and then deleted the stash with git stash drop.
我使用的技巧是执行 git stash 以撤消所有更改(包括恢复 mv'd 文件),然后使用 git stash drop 删除存储。