Retract accidental checkin

2019-01-03 06:12发布

You're using subversion and you accidentally checkin some code before it's ready. For example, I often: a) checkin some code, then b) edit a little, then c) hit up, enter to repeat the previous command which unfortunately was a checkin.

Is it possible to retract such an accidental checkin from the server with subversion?

标签: svn
11条回答
男人必须洒脱
2楼-- · 2019-01-03 06:36

If what you meant is, how do I cleanly remove the history of an accidental checkin: This is difficult.

svn does not allow you to undo anything since it saves revisions as changesets. However, there are some tools that let you do almost anything on a dump of a repository. You could:

  1. Dump your repo.

  2. Use svndumpfilter from the svn admin tools to get rid of the checkin.

  3. Put it back into the repo.

But this can completely ruin your repo, so never ever try to do this, unless you absolutely know what you are doing and have everything backed up.

查看更多
▲ chillily
3楼-- · 2019-01-03 06:37

Using TortoiseSVN, select Show log and locate the revision that you want to revert to. From the context menu, select Revert to this revision. This performs a reverse merge into your working copy, so you will have to commit your working copy to finish the operation.

See also How do we keep track of our working copy's branch? :-)

查看更多
走好不送
4楼-- · 2019-01-03 06:39

You cannot remove the revision - several answers here seem to be totally misunderstanding what you want. But you can change the checkin message to indicate that it it was unintended. Checkins don't cost very much so having the odd extra one is no big deal.

查看更多
手持菜刀,她持情操
5楼-- · 2019-01-03 06:39

To comment on this as well: This is a series of commands that I did on a repository to revert it from revision 2 back to revision 1. You'd need to checkin at the end as well though.

Last login: Mon Apr 13 16:01:34 on ttys004
[wlynch@orange ~] cd /tmp
[wlynch@orange /tmp] svnadmin create foo
[wlynch@orange /tmp] svn co file:///tmp/foo foo-repo
Checked out revision 0.
[wlynch@orange /tmp] cd foo-repo/
[wlynch@orange foo-repo] ls
[wlynch@orange foo-repo] touch blah
[wlynch@orange foo-repo] touch repl
[wlynch@orange foo-repo] touch bar
[wlynch@orange foo-repo] svn add *
A         bar
A         blah
A         repl
[wlynch@orange foo-repo] svn ci
Adding         bar
Adding         blah
Adding         repl
Transmitting file data ...
Committed revision 1.
[wlynch@orange foo-repo] echo "hi" > bar
[wlynch@orange foo-repo] echo "oh no" > blah
[wlynch@orange foo-repo] svn ci
Sending        bar
Sending        blah
Transmitting file data ..
Committed revision 2.
[wlynch@orange older-foo] svn diff -r 1:2 file:///tmp/foo
Index: bar
===================================================================
--- bar (revision 1)
+++ bar (revision 2)
@@ -0,0 +1 @@
+hi
Index: blah
===================================================================
--- blah    (revision 1)
+++ blah    (revision 2)
@@ -0,0 +1 @@
+oh no

[wlynch@orange foo-repo] svn diff -r 1:2 file:///tmp/foo | patch -R
patching file bar
patching file blah    
查看更多
祖国的老花朵
6楼-- · 2019-01-03 06:40

you cannot retract the revision, the most you can do is revert back to prior revision and do another checkin.

查看更多
登录 后发表回答