How to restore a modified file in geany on linux? - linux

I have modified a file (personal file) and I saved the modification, now I want to restore the file to its last status before the modification, is it possible? how?

Which distro?
I mean if you are using gedit text editor and you have backup option turned on it then go to the directory of your file and switch to "show hidden files and folders" and there should be a backup. for example if the file name is 1.txt, backup would be 1.txt~. It will contain the stuff before the last save,

As far as I know, Geany does not keep a backup of files by default while saving, so your file changes are probably lost.
Geany however does have a plugin which can do this for you in future. You can enable the Save actions plugin and enable the Backup copy option in it.

If you have just overwritten the file (Ctrl+S) and haven't yet quit Geany, you can just Ctrl+Z to the desired document state and save that file version.
If you have already quit Geany after that and haven't set up back up in Geany before, I am afraid that by means of Geany you cannot restore the file to the previous state.
Read this article about how to set up back up in Geany. Basically you can go to Edit -> Preferences -> Various (read the manual and the link above before changing these preferences) and:
disable use_atomic_file_saving (disabled by default)
enable use_gio_unsafe_file_saving (enabled by default)
enable gio_unsafe_save_backup (disabled by default)
This will always keep the previous version of the file (as a hidden file with ~ attached to its name) next to original.
Or you can install/enable the Save Actions Geany plugin and enable the Auto Save and Backup Copy options to automatically save files at a certain time interval and to keep a copy of previous file versions.

Related

Perforce not downloading file even with forced Get Revision

After too much time of searching what could be the cause of a really strange but simple-looking problem and not finding anything on the internets, I came here to dip in the knowledge of the people of StackOverflow. Here is my situation:
In P4V, I right-click on a file > Get Revision... > Get latest revision selected, with Force Operation (replace file even if you already have the revision specified) checked.
But then, in the console panel: file(s) up-to-date. no files updated
What is going on? What is the Force Operation option for, if it doesn't force the operation?
The red check mark indicates that the file is open for edit (or “checked out” in P4V’s parlance), which protects it from being updated by a sync operation (that’s “get” to P4V). The “force” sync option will overwrite a file that’s manually been made writable, or a file whose contents have accidentally gotten out of sync with the depot through some other misadventure, but it will not overwrite a file that has been explicitly opened for edit, since an opened file is assumed to have local changes that have not been submitted.
Right-click the file and “Revert”. That will explicitly discard your local changes and return the local file to its state as of the last time you synced it from the depot.

Can you prevent P4Merge from jumping back to the top of the file when editing the workspace file?

I have a long standing issue with P4Merge. When I diff a workspace file with the version in the depot and then proceed to edit the workspace file, within P4Merge, after every edit and save the cursor jumps back to the top of the file. This force me to navigate back to the last diff I was at.
So the steps are something like:
Diff workspace file with depot version
Edit workspace file by pressing Edit File (in right pane) button
Edit the workspace file
Save the file (ctrl+s)
The result after step 4 is that you are automatically scrolled back to the first change in the file and have to track back the change you were previously focused on.
Is there any way to prevent this from happening? I.e. I just want to stay at the current line and be able to proceed to go to the next or previous change from there.
No, there is not a way to prevent this -- sounds like a bug more than anything.
As a workaround you can configure other merge tools to use with Perforce. Since you're on Windows my personal recommendation would be P4WinMerge (the merge tool that used to be bundled with P4Win -- I always found it a lot less "jittery" than the newer one so I never bothered to switch over), which you can still download thanks to the Wayback Machine:
http://web.archive.org/web/20160703111618/http://filehost.perforce.com/perforce/r07.2/bin.ntx86/p4winst.exe

Vim do not set syntax to file any more after crash?

My System was crashed yesterday, the problem is that syntax is disable and set autoindent is not in use.
Even I remove this file, touch this file again, it remains not right!
Swap files are not meant to edit directly.
Swap files are special files that store pieces of Vim's state, and pieces of the unsaved file, in a Vim-specific format. These are not backup files.
You may be able to use the swap file to recover any edits-in-progress. To do that, simply edit the file you were editing when your system crashed. Vim will detect the swap file and prompt you to recover the file if it is able to do so.
That is, if you haven't invalidated the swap file format attempting to edit it in a misguided attempt to recover your file from it by hand.
Now, Vim does have a separate ability to make real backup files that are copies of your file, whenever it saves. But that doesn't help you from a system crash, that helps you when you mess up your file yourself while you edit, and then save it.
There is also a proposed new feature (in the todo list) for adding a command to recover an entire file from an undo file, if the file itself got deleted somehow, but that's not included in any released Vim yet.

Why does a log file have the extension swp?

My log files are generated inside a particular directory on my Linux server. Sometimes when I view the log files inside that directory using ls -lart, I see:
abc.log
.abc.log.swp
Could anybody please explain why the log file has the name .abc.log.swp?
Those are vim "swap" files -- temporary files created by vim while you are editing a file. They are (usually) removed automatically when you exit the editor.
When you edit a file using vi and some other editors, the editor creates a temporary swap file with the .swp extension. If something goes wrong and the editor crashes or the computer dies, the swap file contains your changes so you can revert back to the edited file.
As soon as you close the editor, the swap file should be deleted. If it isn't, and you didn't experience a crash, you can simply remove the swap file.

How to discard perforce integration history for a newly-branched and edited file?

Let's say I've branched a file in perforce and edited it. Now I'd like to discard the branch history and treat the file as a fresh add. What command accomplishes this?
This scenario arises often because my IDE insists on treating a copy as a branch/edit. After making extensive changes to the copied file, it causes confusion to treat it as a branch/edit.
You can revert the new file and then add it back, without the copy/move.
cp /path/to/new/file /path/to/new/file.bak
g4 revert /path/to/new/file
mv /path/to/new/file.bak /path/to/new/file
g4 add /path/to/new/file
But, the history is there for a reason. If one exists, you might want to keep it - it might be helpful to see the lineage (even if muddled) at some point in the distant future. Consider changing your settings on your IDE.
In your IDE:
Create a new file with the new name
Open the old file
Select the contents of the old file
Copy to the clipboard
Open the new file
Delete all the contents from the new file
Paste in the contents of the old file.
Then the IDE will do a new in perforce instead of a branch, the above is only a few keybaord presses if you use your IDE keybaord shortcuts.

Resources