2

Is there any way to move classes from one source code file to a new one without losing version control history? We are using TFS.

Thanks.

abenci
  • 8,422
  • 19
  • 69
  • 134

3 Answers3

2

It's based on which version control system you are working with:

This not possible with TFVC as Marvin Glenn Lacuna also described very clearly above, However you could try the following workaroud:

  • Branch FileX to FileA
  • Branch FileX to FileB
  • Open each file and delete the party you don't want
  • Delete FileX

Now you could maintain history on all of the visible lines of pre code through the branch relationship.

For GIT, you could take a look at this question: How does git track source code moved between files?

abenci
  • 8,422
  • 19
  • 69
  • 134
PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
0

In TFS, from my experience, the simple answer is no, it stays on the source file and will remain in the source file. It will not be copied to the target file (ctrl+c, ctrl+v). I believe that's why it is called "file history" and not file section/classes history.

Marvin Glenn Lacuna
  • 1,682
  • 1
  • 19
  • 25
0

With current TFS version, the default version control is Git. So you could do it by a trick.

Assume that you have two classes ClassA and ClassB in a file named File.ext, your source code is at branch master. The steps should be:

  1. Create branch 'developA' from 'master'
  2. Call 'git mv File.ext ClsA.ext' then commit to have ClsA.ext with history of File.ext
  3. Cleanup ClassB in ClsA.ext then commit.
  4. Create branch 'developB' from 'master'
  5. Call 'git mv File.ext ClsB.ext' then commit to have ClsB.ext with history of File.ext
  6. Cleanup ClassA in ClsB.ext then commit.
  7. Merge two branches 'developA' and 'developB' then push to 'master'

Now you have both files ClsA.ext and ClsB.ext without losing their history from File.ext. An example could be found at my github repository.

hlv_trinh
  • 11
  • 3