แชร์ผ่าน


Rename command (Team Foundation Version Control)

TFS 2017 | TFS 2015 | TFS 2013

Visual Studio 2019 | Visual Studio 2017 | Visual Studio 2015 | Visual Studio 2013

The rename command changes the name or the path of a file or folder. You can use the rename command or the aliases move or ren, to move a file or folder to a new location.

Note

The results of this command are not reflected in the Team Foundation version control server until you perform a check-in operation. For more information, see Develop code and manage pending changes.

Prerequisites

To use the rename command, you have the Check out permission set to Allow. For more information, see Default TFVC permissions.

Syntax

tf rename [/lock:(none|checkout|checkin)] [/login:username,[password]] olditem newitem

Parameters

Argument

Argument

Description

olditem

The original name and path of the file or folder that is to be renamed. You can specify a local workspace path such as C:\myfiles\314.cs or a Team Foundation version control server path such as $/myfiles/314.cs.

newitem

The new name of the file or folder. You can use this to specify a different local or a Team Foundation version control server path location.

username

Provides a value to the /login option. You can specify a username value as either DOMAIN\UserName or UserName.

Option

Option

Description

/lock

Include this option to prevent other users from checking in or checking out the specified items. If this option is not specified, the existing lock status of the item is not changed. For more information, see Understanding Lock Types.

Lock Options:

  • None No lock is applied.
  • Checkin Other users can check out the specified items but they cannot check in revisions to locked files until you release the lock by performing a check-in. If any other users have locked any one of the specified items, the lock operation fails.
  • Checkout Prevents other users from checking in or checking out any one of the specified items until you release the lock by performing a check-in. If any other users have locked any one of the specified items, the lock operation fails.

/login

Specifies the user name and password to authenticate the user with Azure DevOps.

Remarks

You can use the rename command of the tf command-line utility to move or rename a version-controlled item in your workspace. Use the rename command to move multiple files by specifying wildcard characters. The ability to rename multiple version-controlled files or folders, is only available from the command-line.

Use the rename command to do the following:

  • Rename the olditem to the newitem, such as tf rename 314.cs 315.cs.
  • Move the olditem to a new location in the Team Foundation version control server by providing a newitem whose path differs from that of the olditem, such as tf rename 314.cs ..\\newdir\\314.cs.

If you provide a newitem that specifies a non-existent folder, the rename command creates the destination folder. If newitem is a folder, olditem becomes a child of newitem.

You cannot rename an item if:

  • You have already deleted it before it was checked in to the same workspace.
  • The new name already exists in the Team Foundation version control server and is not a folder.
  • You have already added, branched, or renamed the pending check-in of the item.
  • The item is mapped in the workspace but not available on the local disk.
  • The item is cloaked.

You can rename an item for which another file of the same name has been added pending check-in but you cannot rename an item that has been branched but not yet checked in. When you rename a file that has pending edits, the edits are preserved.

An item that is explicitly mapped cannot be renamed without first changing the mapping. For example, if there is a working folder mapping of $/ProjectX/MyApp to c:\MyApp, you cannot rename MyApp. You can rename items under MyApp but not MyApp itself.

For more information on how to find the tf command-line utility, see Use Team Foundation version control commands.

Examples

The following example changes the name of 314.cs to 1254.cs.

c:\projects>tf rename  314.cs  1254.cs

The following example renames 314.cs to 1254.cs and moves it to the newdir folder.

c:\projects>tf rename 314.cs ..\newdir\1254.cs

The following example changes the name of Form1.vb to MainPage.vb and applies a lock to it.

c:\projects>tf rename Form1.vb MainPage.vb /lock:checkin