VsCode - Source control shows multiple copies of file changes - visual-studio-code

For some reason, whenever there's a change in a file, VsCode creates multiple copies for each change which are shown in the source control, I don't know why has that started to happen:

A vsCode extension called Local History for maintaining local history of files, when enabled, creates a copy of the old contents kept in the local history, every time you modify a file.
Disabling the extension was the solution here! :)

Related

Set not tracked folders and files in perforce as writable

I already have some folders that often need to be rewritten and are local in my .p4ignore however they are still always automatically marked as not writable. how can i exclude these files that are not on the server and not tracked from being made none writable. a file like this would be the unreal autosave folder for example
These files aren't really "untracked" the way you currently have things set up. If the files are being made readable, it means that somebody else has added them to the depot and you're syncing them down. .p4ignore stops you from adding files from your workspace, but it doesn't stop anyone else from adding them to the depot and it doesn't stop you from syncing them down.
Luckily Perforce allows you to configure what files are and aren't part of your workspace. Edit your client view to exclude the files; the next time you sync they'll be removed, and from that point on you'll only ever see files there if you put them there yourself; Perforce will not touch them, including making them read-only.
https://www.perforce.com/perforce/r13.1/manuals/p4v/Defining_a_client_view.html
https://www.perforce.com/perforce/r14.3/manuals/p4v/streams.views.html
https://www.perforce.com/perforce/r12.1/manuals/cmdref/o.views.html#:~:text=To%20create%20a%20client%20view,to%20evolve%20along%20different%20paths.
Once your client view is configured correctly, .p4ignore is no longer necessary. If you're using streams, configuring the stream view to exclude unwanted files will automatically propagate the change to all workspaces of that stream.

Sourcetree, View file in old version/commit

How do I view a particular file from a particular commit/version?
I have seen the solution where you view the file in (any) History, right-click it and select Log Selected and then choose Open Selected Version. However, this only works when I can find the file in History, which means I need to find a commit/version where the file was updated. I don't have this info.
I have also seen solutions where I can checkout the old version. However, I'd like to avoid this. I have current files open in editors and want to keep them there, unchanged. Generally, I find that checking stuff out and creating new branches sometimes creates annoying head/branch/whatever errors that I'd just as well avoid just to view a single old file.
I used to use TortoiseHG where I could right-click any version, choose to view the files in that version, get a window showing all files, and then open any file from there as a temp file.

very simple file version control

I'm looking for a way to do version control on a set of files, but not for project history, more of an extended undo. Basically I'm looking for a very simply version control with little overhead that will watch a directory for changes then save the differences so I can go back and view any file at any save. I don't want all the features of git or another version control like it. Also I don't want to have to commit changes, changes should be save as soon as a file is modified. Any suggestions?
I'm contently running into situations I write a block of code, save the file, rewrite the block of code, save the file, then realize I need it like it was at first but can't undo in my text editor for some reason.
Dropbox has a very simple version control only for files. You can revert to any previous version and every time yo save changes and updates the file it creates a new version. You can work on Dropbox folder to do this automatically

TFS deleted my files when changing the mapping

I had quite a big solution with a lot of code here. Because of some issues with TFS I wanted to create a new 'clean' repository. I removed the mapping to the old repository, and tried creating a new mapping. This resulted in an error that there already was a mapping to my solution. I went to the Source Control Explorer -> Workspaces and deleted the mapping to my solution there. After that I was able to map my new repository to my solution.
But when I checked my hard disk I almost had a heart attack: TFS deleted ALL my code files! The directories and dependencies were still there, but all my project files, my solution file and all of the code was gone!
Please StackOverflow, help me out here! This is a LOT of work that is now gone and I really desperately need it back :(
Edit: I'm currently trying to recover my files with a couple of file recovery tools (like Recuva), but none of them can find any deleted changes. But the files are really gone, Windows search doesn't find them, and they aren't hidden either. Can anyone tell me why this is? Are the files still on my SSD then?
Source control systems like TFS all work along very similar lines. They treat the server's version of the code as "the code" - it's the master copy, and is "owned" by the server. You can then get a copy of the code on your PC (by adding a workspace mapping you tell it where you want it to put this copy). You can make changes to your copy of the code, and then check them in to apply them back to the master version of the code on the server.
So if you change a workspace mapping (e.g. change the location of your copy of the code from folder A to folder B), what you are telling the source control system is "please take away the copy of the code that is in location A, and put it in B". So this is why it deleted all "your" code. It wasn't "your" code, it was a copy of the server's code - you asked it to put it somewhere else on your PC ... so it did.
However, if you had edited any of the code in your workspace, the files would have been checked out, in which case TFS would have known that you had pending changes, and it shouldn't have deleted those files - it should have reported an error as you were trying to change a workspace mapping that included pending changes.
The only way this wouldn't happen is if you manually changed the files to be writable and made changes to them outside of Visual Studio/TFS, so that TFS did not know you had made the changes. If you "secretly" changed some files, TFS may have thought they were unchanged, and therefore permanently deleted them. These files may not show up in file recovery tools because by asking TFS to relocate the workspace you got it to delete the files and then immediately re-get them (into a new folder), which will almost certainly have overwritten the data of the deleted files.
If your changes might have been checked in, then you can find them like this: go to your Team Project in the TFS Source Control view. Right click the Project and choose the "View History" option. This will list all checkins to the project in reverse historical order - if you checked in, then you should see your checkins here. (You can double click any changeset entry in the history to view the list of files that were changed, and if you right click any file you can "Compare..." to see a diff that illustrates exactly what changes were made)
If the changes are not in your checkin history, then I'm afraid you've lost them.
You've probably already learned this, but it's important to learn to use tools like source control properly - they are useful and powerful tools, but they can be dangerous if you don't understand how they work.
If you checked all in before you removed the mapping. The source is almost in the repos. But if not it is already gone sorry :(
Sorry for your loss.
TFS didn't delete anything. You simply never checked it in. If TFS had "deleted" your code, then you would be able to see your code in the history in Source Control Explorer. You would see that there was a changeset with "Delete" operations against your code.
You would then be able to roll back that changeset and get all of your code.

Can I safely edit a renamed file in perforce

I have a file I need to move that's already under perforce. Once moved it needs some editing - update the package, etc - appropriate to its new location. Should I submit the move changespec and then reopen it for edit, or can I do this in one go? If so, what is the appropriate sequence of events?
I have done this before in one go, but depending on your build process, I recommend against it. What I generally do is this:
Move the file.
If the move needs a change in order to compile, open it for edit and make those changes.
Submit the changes, telling perforce to reopen the files for editing.
Make the changes for path, etc., that don't cause compile errors but should be updated.
Submit those changes with an appropriate description.
If you want to, however, you could just do all your changes in step (2) above. Perforce might change the flag for the new file from integrate to add, but it still remembers the source path for the file.
Edit: Better method
I realized that I often use a different method, but the idea of "moving" the file distracted me. So, I would recommend these steps instead:
Integrate the file into the new path/name, leaving the previous file there. I am assuming that this won't break your build process.
Submit the new file, checking it out again for edit after submission.
Make the required changes to the new file, and to the project so that you are using the new file.
Submit the edits for the new file.
[Optional] You might need to check through branch specs to see if you need to map the old file into the new one in any branches.
Create a changelist for deleting the old file, and submit it sometime later.
This method allows the edits to be cleanly separated from the rename/move, while never leaving the project in a state that won't compile.
Also, why wait for step 6? Sometimes, especially on bigger projects, you might want to move a file that another person is editing. Perforce will helpfully tell you this. By waiting to delete the file, you allow your coworker(s) to finish the edits and submit without needing to move their work manually. After the edits are submitted, they can be integrated into the new file, and then the old one can be safely deleted.
Submit the move change and then reopen for edit (you could use the reopen option too).
This is much more readable to the user in the change history.
Also, recent versions of Perforce do perform checks for changes to files after resolution. So, there may be complaints editing files after some resolve operations have been completed.
I would say always submit first then edit. It is much cleaner and makes it more obvious whats happening in your repository. Then simply checkout the file in the new location and make whatever changes. This also makes it much more obvious that the changes were made in the new location and to all it to work after renaming.
Yes you can. Simply reopen for edit the branched file (i.e. the new one). In P4Win, there is a context menu for this ("re-open for edit").
"Safely" is probably an important point here. Once you rename or move the file it'll get a revision number of "1" which looks like a new file to your Perforce client. Of course, admins will be able to get its prior history, but if the editing/version history of the file is important to you it's a little harder to get the older revision.
Update: Thanks to Commodore Jaeger and Greg Whitfield for enlightening comments.
This wasn't easy to track down regarding what the One True Answer is, even from Perforce support, so I figured I'd update everyone on what we found:
Perforce stores all versions of every document in its database.
If it's saving your file as type <text> or <ktext> then it stores the diffs of one file version to another and not the entire file.
If you check out a file, make no changes to it, and then re-submit, it will save as a new version with 0 diffs. This is configurable and P4 can be set up to ignore changelist items without any actual diffs. You can force this behavior by selecting "Revert unchanged files..." before you submit a changelist.
Use "Rename/Move..." to move files in P4 so it can track them. Don't copy them using Windows Explorer and then re-add them in P4.
If you use the "Rename/Move..." function from the context menu, the "new" file will show a revision number of "1" as though it were a new file.
However, since P4 saves every function performed on a file, you can actually get to any previous revision (and even recover "deleted" files) with the CLI command p4 filelog -i
If you want to get to the revision history of a moved or renamed file and you're not an admin, you can right-click and select its "Revision Graph" which shows every version of a file even when moved between branches.
According to Perforce support, easier tracking of revision history through branch or folder moves is an oft-requested feature and is in their current roadmap.
Perforce's answer: At the moment, there isn't a way to move/rename/integrate files and still maintain the exact file history.
However, if you were to choose "Integrate..." by right-clicking on the folder that you want to share, the versions of the files of the newly branched folder and underlying files will start from revision #1, but the integration history between the branched folder and underlying files and the original folder and underlying files will remain through which you can trace the revision history of the files.