开发者

deleting and renaming files

When working with a checked-out copy of an SVN or Git project, I often delete or rename files witho开发者_C百科ut using the appropriate git mv, svn rename, git rm, or svn delete commands, so these changes are not appropriately reflected when I commit my version back to the repository. Is there a workaround to fix this after the fact, besides being more careful on my end?


For Git, have a look at git add -A. This will add everything which is new or changed, as well as removing files which are not there anymore. It might also add files you don't really want to add, though, so be careful here. As git does not track renames explicitly, this should be enough (together with a git commit).

For Subversion, you could do something like svn add --force . followed by a svn commit to do the equivalent, but this will not track renames/moves properly. I think it is not trivial to find out which files were renamed (and maybe changed as well) and which were simply added/removed.


With git, git mv is just a convenient alias and is equivalent to moving a file and doing a git rm on the old file. If you omit using this, the result is you deleted the original file, which git will notice, and added a new file, which git will ignore because you haven't called git add. git rm is similar.

This is one of the downsides of git since it does not force you to commit every change in your repository as other version control systems do. However, it can be easily managed with the git status command and careful use of .gitignore files. So long as you keep your tree clean, or appropriately ignored, you can tell at a quick glance whether you have any untracked files that you missed.

As far as fixing this after the fact, just stage and commit the appropriate changes, which in this case will be untracked files.


In git if you have deleted files, you can use git commit -a and the commit will reflect the deletes without having to do a git rm

Gui tools like TortoiseSVN and TortoiseGit are smart about such things and you generally don't have to do explicit delete and renames when using such tools.


For git, once you removed a file, use:

git rm --cached myfile
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜