Mercurial: rename, then create a new file with the old name

I am using TortoiseHg. I have file A. I used the rename tool to rename it to B. Everything seems to be fine. Now I want to create a new file with the name A. When I create a file with this name and proceed to add it to the repo, it shows me the difference of my new file with old A (which is now renamed B.)

How can I rename A to B and be able to add a new A, which is, y'know, new and does not have Hg, I think that I am changing the old, now non-existent A?

Edit: Actually, what I originally did was correct, I just did not perform the renaming properly. (I committed, but only transferred the recently renamed file, and not the now defunct old file.)

+4
source share
2 answers

You need to commit after renaming, and then create a new file with the same name.

$ hg mv AB $ hg commit -m "moving A→B" $ touch A $ hg add A $ hg commit -m "adding new A" 
+3
source

Suppose you are using the a.txt file in your repository. To rename it to b.txt and add another file named a.txt using TortoiseHg 2.x, follow these steps:

  • Right-click a.txt . In the context menu, click TortoiseHg > Rename File .
  • In the Rename dialog box, enter b.txt in the Destination text box. Click Rename .
  • Right-click the repository folder. In the context menu, click Hg Commit .
  • In the Commit window, make sure you have two files, added b.txt and deleted a.txt . Enter a description of the commit and click Commit . Close the Commit window.
  • Create a new file named a.txt . Right click on it. In the context menu, click TortoiseHg > Add Files .
  • In the Add window, make sure a.txt . Click Add .
  • Right-click the repository folder. In the context menu, click Hg Commit .
  • In the Commit window, mark a.txt . Enter a description of the commit and click Commit . Close the Commit window.

Now you have another a.txt with a fresh story and b.txt that remembers that it was named a.txt .

PS These are the same steps as Vaibhav Baipai in his answer. You may have a hard time if you have problems with actions expressed in hg commands.

+3
source

All Articles