How to "undo" a file in svn and / or git

It happens to me all the time. I accidentally version of a file, I do not want to be a version (that is, the developer / machine specific configuration files).

If I commit this file, I will ruin the paths on all other development machines - they will be unhappy.

If I delete a file from the version, it will be deleted from other development machines - they will be unhappy.

If I decide to never commit the file, I always have a dirty check - I am not happy.

Is there a clean way to β€œundo” a file from version control, which will cause no one to be unhappy?

edit: an attempt to clarify a bit: I already sent the file to the repository, and I only want to remove it from the version - I specifically do not want it to be physically deleted from everyone who checked. At first I wanted to be ignored.

Answer. If I could accept the second answer, that would be this . It answers my question regarding git - accepted answer about svn.

+61
git version-control svn versioning
Aug 26 '08 at 10:20
source share
15 answers

SVN version 1.5 supports deleting / deleting a file from the repository without losing the local file

taken from http://subversion.tigris.org/svn_1.5_releasenotes.html

The new --keep-local option saves the path after deletion.

Delete (delete) now accepts the -keep-local option to save its targets locally, so the paths will not be deleted, even if they are not modified.

+33
Jun 30 '09 at 21:59
source share
β€” -

In Git, to remove it from the tree, but NOT from the working directory, which I think you need, you can use the -cached flag, i.e.:

git rm --cached <filename> 
+53
Jun 04 '10 at 22:27
source share

If you accidentally "added" a file to svn and you did not commit it, you can return this file and delete it.

+8
Aug 26 '08 at 10:21
source share

Without trying ...

In git, if your changes were not propagated to another repository, you should be able to git rm affected file (s), git rebase --interactive , to change the order in which the git rebase --interactive right after the commit to which you accidentally added abusive files, and then squish these two commits together.

Of course, this will not help if someone pulled your changes.

+7
Aug 26 '08 at 10:47
source share

It looks like you have already added and moved the file to subversion (I assume you are using Subversion). If so, then there are only two ways to delete this file:

  • Mark the file as deleted and commit.
  • Run svnadmin dump , filter out the version in which you accidentally committed the file, and run svnadmin load .

Believe me, you really do not want to do number 2. This will invalidate all working copies of the repository. It's best to do number 1, mark the file as ignored and apologize.

+5
Aug 26 '08 at 10:52
source share

Take a look at svn: ignore and .gitignore - these functions allow you to have additional files in your control that are ignored by your RCS (when performing the "status" operation or something else).

For machine-specific configuration files, a good option is to check the file with the additional extension ".sample", ie config.xml.sample . Individual developers will make a copy of this file in config.xml and configure it for their system. Using svn: ignore or .gitignore, you can ensure that the file without the config.xml conversion does not appear dirty all the time.

In response to your editing: if you now delete the file from the repository, your developers will get a conflict during the next update (provided that they all changed the file for their system). They will not lose their local changes, they will be extracted somewhere. If they have not made any local changes, their configuration file will disappear, but they can simply reuse the previous source control and use it.

+4
Aug 26 '08 at 10:26
source share

To completely remove a file from the git repository (let's say you wrote a file with a password in it or accidentally ran temporary files)

 git filter-branch --index-filter 'git update-index --remove filename' HEAD 

Then I think you need to commit and press -f if it is in remote branches (remember that it can annoy people if you start changing the repository history .. and if they pulled you out earlier, they might still have a file )

+4
Aug 30 '08 at 12:08
source share

To delete a file that is already in the source control:

 git rm <filename> 

and then

 git commit -m ... 

You must add each file that you want to ignore to the .gitignore file. I also always check the .gitignore file for my repository, so if someone checks the code on their computer and the file is generated again, he will not β€œsee” it as β€œdirty”.

Of course, if you already made a file, and someone else got your changes on another computer, you will have to change each local repository to change the history. At least this is a possible solution with git. I do not think svn will allow you to do this.

If the file is already in the main repository (git) or on the server (svn), I don't think there is a better solution than just deleting the file in another commit.

+3
Aug 26 '08 at 10:24
source share

For SVN, you can return files that have not yet been saved. In TortoiseSVN, you simply right-click the file in the commit window and select Revert ...

At the command line, use svn revert [file]

I don’t know about GIT since I have never used it.

+2
Aug 26 '08 at 10:24
source share

As far as I know, there is no easy way to remove the added file from version control in svn after it is committed.

You will need to save the file elsewhere and remove it from version control. Then copy the backup again.

This is a version control system after all ...;)

+1
Aug 26 '08 at 10:25
source share

You can exclude files from a disruptive program with a global ignore option
http://svnbook.red-bean.com/en/1.1/ch07.html#svn-ch-7-sect-1.3.2
read the documentation for details

+1
Aug 26 '08 at 10:27
source share

I'm there, I decided to never transfer the file, I always have a "dirty" check - I'm not happy.

Regarding this particular point, you may want a .gitignore file, as others have suggested, or use a circuit similar to the one described in this answer .

+1
Aug 31 '08 at 12:11
source share

Two simple steps in SVN:
1. Add this directory to the parent directory svn: ignore property:

 svn propedit svn:ignore . 

2. Delete the directory:

 svn rm mydir 

3. Commit

Please note that when other developers perform svn update , this directory will not be deleted. SVN only deploys it.

+1
Mar 21
source share

You can expand all the files in the current directory with this command. The sed bit changes order, so svn can handle it:

 find . | sed '1!G;h;$!d'| awk '{print "svn rm --keep-local " $1}' 

As mentioned in other answers, one file was not converted using this:

 svn rm --keep-local yourFileNameXXX 
0
Mar 09 '16 at 12:13
source share

On Windows, if what you are looking for copies the folder to another location and deletes it from git so that you no longer see the icons, you simply delete the .git folder. The .git folder is hidden, so you need to go to the "Organize / Folder and search options", "Show hidden files" in the main folder. He must cancel it.

0
Dec 06 '16 at 5:31 on
source share



All Articles