Recent

Author Topic: How to revert my mess (repository)  (Read 806 times)

Nicole

  • Sr. Member
  • ****
  • Posts: 351
How to revert my mess (repository)
« on: July 12, 2022, 07:15:38 pm »
I am new in Lazarus and old in Delphi.
In Delphi I used to save every important step as "my_pas_sic.pas".
The dfm was saved by the machine. I save the file back to the original name and had my revert point called _sic (for 'Sicherung').
Very slim solution, a handful of KB. A few seconds of work.

This does not work in Lazarus that way.

What would you recommend me as backup for snapshots and backup for source?
I would like to:
1) Generate snapshots to revert if I brought myself into a dead end once again? - for work in progress
2) Which files shall I include in backups? lpr, pas, lfd..... is there a list anywhere? - for finished coded projects

It shall remain as slim as possible.
Thanks.

af0815

  • Hero Member
  • *****
  • Posts: 1022
Re: How to revert my mess (repository)
« Reply #1 on: July 12, 2022, 07:29:21 pm »
In short: think about git

It is meaningless if you use Lazarus , Delphi, Visual Studio or .... Only a sourcecode managment give you the tools to have control about your code. And you didnt need your own server, for the first steps. Or you use one of the popular (free) Hoster like GITHub or GITLab. There you can have privat repositories for free (read the rulez)
regards
Andreas

Thaddy

  • Hero Member
  • *****
  • Posts: 11928
Re: How to revert my mess (repository)
« Reply #2 on: July 12, 2022, 08:53:04 pm »
And short-term mess can be resolved with crtl-z , meaning typos or errors in your session. Goes quite deep... more that 10 edits.
(BTW for individual programmers it is better to - imho - still use svn instead of git)
« Last Edit: July 12, 2022, 08:57:13 pm by Thaddy »
Black themes should be banned.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 8260
  • Debugger - SynEdit - and more
    • wiki
Re: How to revert my mess (repository)
« Reply #3 on: July 12, 2022, 09:07:07 pm »
1) Lazarus does save copies to a backup folder, and you can configure that. You can set it to keep the last 500 "saves" of each file.
However, that includes when the file gets saved for compilation.

It's gonna be a mess though to find the correct one...

2) Saving and restoring copies.
Not sure what you mean "it doesn't work" => well you probably can't do "Menu: File > Save as". But you can copy files in your filesystem/explorer.

3) local version of git. (no server needed / though nice as backup)
On Windows with tortoise git, that is really easy.
Just do a commit every time you made a change.
Later rebase them, and squash them.

PascalDragon

  • Hero Member
  • *****
  • Posts: 4562
  • Compiler Developer
Re: How to revert my mess (repository)
« Reply #4 on: July 13, 2022, 09:03:41 am »
(BTW for individual programmers it is better to - imho - still use svn instead of git)

Git does not require a server, SVN does. For simple usage there isn't otherwise that much difference between the two, but if one needs a bit more (e.g. cleaning up the history) Git has you covered already. I personally see no reason to recommend SVN instead of Git to lone developers.

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1086
Re: How to revert my mess (repository)
« Reply #5 on: July 13, 2022, 12:06:23 pm »
It is very easy in Git to make a mistake and lose all your work. As long as you only check in periodically, you're probably fine. Everything more than that is dangerous.

af0815

  • Hero Member
  • *****
  • Posts: 1022
Re: How to revert my mess (repository)
« Reply #6 on: July 13, 2022, 12:10:52 pm »
Git does not require a server, SVN does.
For simple usage, you can use the "file://" Protokoll special for Tortoise SVN instead a server. For a single user maybe acceptable.

(Source: https://tortoisesvn.net/faq.de.html#reponoserver in german)
regards
Andreas

PascalDragon

  • Hero Member
  • *****
  • Posts: 4562
  • Compiler Developer
Re: How to revert my mess (repository)
« Reply #7 on: July 13, 2022, 01:58:01 pm »
It is very easy in Git to make a mistake and lose all your work. As long as you only check in periodically, you're probably fine. Everything more than that is dangerous.

I have yet to manage that and privately I use Git quite a bit longer than when FPC/Lazarus switched over to Git.

Git does not require a server, SVN does.
For simple usage, you can use the "file://" Protokoll special for Tortoise SVN instead a server. For a single user maybe acceptable.

(Source: https://tortoisesvn.net/faq.de.html#reponoserver in german)

I wasn't aware of that, but even then I'd still prefer Git there, cause if I need remote abilities everything is already there (e.g. pushing the repository to a separate computer for testing).

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 8260
  • Debugger - SynEdit - and more
    • wiki
Re: How to revert my mess (repository)
« Reply #8 on: July 13, 2022, 02:26:33 pm »
It is very easy in Git to make a mistake and lose all your work. As long as you only check in periodically, you're probably fine. Everything more than that is dangerous.

Off topic, but IMHO not true.

1) git with server (compare with svn(
If you do push, then your git data is as save as any svn data is.
If you "screw up" your local site: Backup, Delete, and clone from server.
Btw "screw up" means simple getting your repo into a state where you as beginner do not know how to get back to access the data (it's not lost, you may just not know how to access it / you can still ask for help).

I am aware of "force push", but even then:
- As a beginner you are unlikely to do force push.
- Yet if you done that, the safety nets below still apply (client and some server side).

2) Local only.
The only mistake, that really will loose all your data: Delete the (contents of) .git directory.

Btw, If your svn server runs locally, you can do the same with the svn server dir.
And if you want a 2nd local dir, with git you can push to a 2nd repo dir, without needing a server.

Anything other that the above "delete .git" mistake, and your data is still in git. 
(Well, ok, if you do force a (IIRC) "git prune --expire=now" ... but then again, if you know that command, you know where your data is)

If you screw up, you may have to ask how to get your data. But it is still there.

- local git has a "reflog" for each branch (by default 6 weeks). So anything you had in those 6 weeks will be in there (as long as you still have the branch / or if it was reachable under HEAD).

- git (local and server) keep data, even if you delete the (only) branch that holds the data (or reset the branch, and even if you made other commits, or amend a commit, or....).
IIRC by default for 2 weeks.
You can get it back (like undelete for a filesystem). You need the sha1, which "git fsck" can get you.





The only thing that does apply is: There are certain mistakes a beginner can easily make under git, and as a result of those you might easily get your repo into a state that you will need help to recover from.
This is IHMO especially true, if you still insist on learning the old "git checkout" command, rather than the newer "git switch" / "git restore" commands.


avra

  • Hero Member
  • *****
  • Posts: 2368
    • Additional info
Re: How to revert my mess (repository)
« Reply #9 on: July 13, 2022, 02:31:42 pm »
What would you recommend me as backup for snapshots and backup for source?
I would like to:
1) Generate snapshots to revert if I brought myself into a dead end once again? - for work in progress
2) Which files shall I include in backups? lpr, pas, lfd..... is there a list anywhere? - for finished coded projects

It shall remain as slim as possible.
Although GIT is recommended, there are times when you need to complement or replace it with a simple backup solution. Copy below code to arc.bat file, have 7z command line executable from 7-zip package somewhere in the path, adapt BAT file to your needs, and call that BAT file each time you need to archive your project. It will create YYYYMMDD.zip file according to current date, and you can add your comments to that file name easily.

Code: DOS  [Select][+][-]
  1. REM archive file name should be: YYYYMMDD.zip
  2. set archivefilename=%date:~10,4%%date:~7,2%%date:~4,2%
  3.  
  4. REM delete old file name if it exists
  5. del %archivefilename%.zip /q
  6.  
  7. REM pack everything important from all dirs to archive
  8. 7z a %archivefilename%.zip -tzip -mx9 *.* -x!*.bat -x!*.exe -x!*.dbg -x!*.log -x!*.db -x!*.bak -x!*.zip -x!*.7z -x!*.mht* -x!*.pdf examples\s7demo\*.* -x!examples\s7demo\*.exe -x!examples\s7demo\backup\*.* -x!examples\s7demo\lib\*.* examples\simple-led-demo\*.* -x!examples\simple-led-demo\*.exe -x!examples\simple-led-demo\backup\*.* -x!examples\simple-led-demo\lib\*.*
  9.  
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1086
Re: How to revert my mess (repository)
« Reply #10 on: July 13, 2022, 04:42:09 pm »
@PascalDragon, @Martin_fr:

I sometimes use Git from the command-line (with a bit of Googling). That tends to work. I used Tortoise Git in the past for a bit, with good results, although sometimes it was a bit confusing. Now I use Sourcetree, and it happened multiple times that I lost my work. Easiest way: double click a different branch. A bit harder: forget to make a branch up front. And I had it once with rebasing, but I don't do that very often. And of course, merging can be a pain, but that has nothing to do with Git.

So I also wrote my own backup program, to run before doing dangerous things. It's a bit more complex than a batch file, but I should add exclusions.

Nicole

  • Sr. Member
  • ****
  • Posts: 351
Re: How to revert my mess (repository)
« Reply #11 on: July 13, 2022, 06:26:28 pm »
Thank you for your answers.
I will learn about GIT. My problem is, that I kill myself. I mess on and on and suddenly a form cannot be displayed any more or so. Or it does not start because a ressource has doubled or is lost. Mess.

About backup, I use this:
personal-backup.rathlev-home.de/

The developer is as smart as kind. Once I mailed him, "your software is the only one, which works for my Delphi backup. No other does".

His answer: "I know. This was the only reason years ago, why I wrote this software for myself."

Thank you for the 7zip list.
My db is in a seperate directory and gets its own backp.

Which files have to be saved for Lazarus and our own projects?
I suggest:
lpr
pas
ldf
[Icons]
ini

Just a worst case thing, case all is lost and I have to renew my programming VM from buttom.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 8260
  • Debugger - SynEdit - and more
    • wiki
Re: How to revert my mess (repository)
« Reply #12 on: July 13, 2022, 06:27:19 pm »
I sometimes use Git from the command-line (with a bit of Googling). That tends to work. I used Tortoise Git in the past for a bit, with good results, although sometimes it was a bit confusing. Now I use Sourcetree, and it happened multiple times that I lost my work. Easiest way: double click a different branch. A bit harder: forget to make a branch up front. And I had it once with rebasing, but I don't do that very often.

I don't know Sourcetree, so I can't comment much on it. I assume "double click" should be a "switch to" (or checkout that branch/commit).

Indeed the most common issue is to switch to a sha, without a branch. (aka detached HEAD) => Been there in my first few weeks, several times. I didn't loose anything, except for a bit of time. But it can feel like things are lost.

Example => If you made a detached commit "forget to make a branch up front"
You forgot to create a branch, before switching away. Commits seem lost. But they are not.

Lets say you have
Code: Text  [Select][+][-]
  1. git log --oneline
  2. 230d446 (HEAD -> master) C
  3. d802048 B
  4. 41345d2 A
  5.  
  6. git switch -d d802048
  7. HEAD is now at d802048 B
  8.  
  9. echo 'ABC' > file
  10. git commit -m B1  file
  11. [detached HEAD 8c6336d] B1
  12.  1 file changed, 1 insertion(+), 1 deletion(-)
  13.  
  14. git log --oneline
  15. 8c6336d (HEAD) B1
  16. d802048 B
  17. 41345d2 A
  18.  

And now you accidentally
Code: Text  [Select][+][-]
  1. git switch master
  2. Warning: you are leaving 1 commit behind, not connected to
  3. any of your branches:
  4.  
  5.   8c6336d B1
  6.  
  7. If you want to keep it by creating a new branch, this may be a good time
  8. to do so with:
  9.  
  10.  git branch <new-branch-name> 8c6336d
  11.  
  12. Switched to branch 'master'
  13.  

First you will note, that it already gives you all the info you need to recover that commit. (Though that is an improvement of the recent years, and a GUI may not tell you...)

If you do notice immediately you can do
Code: Text  [Select][+][-]
  1. git switch -d -
  2. HEAD is now at 8c6336d B1
  3.  
You need the "-d" because the target is detached. The single "-" gets you to the previous checkout.
This is the same as "git switch -d HEAD@{1}"


And then there also is
Code: Text  [Select][+][-]
  1. git reflog HEAD
  2. 230d446 (HEAD -> master) HEAD@{0}: checkout: moving from 8c6336db21a6e8a9a7e174941697d9265a5696d1 to master
  3. 8c6336d HEAD@{1}: commit: B1
  4. d802048 HEAD@{2}: checkout: moving from master to d802048
  5. 230d446 (HEAD -> master) HEAD@{3}: commit: C
  6. d802048 HEAD@{4}: commit: B
  7. 41345d2 HEAD@{5}: commit (initial): A
  8.  

And (if you had made several detached commits) you can
Code: Text  [Select][+][-]
  1. git log --oneline 8c6336d
  2. 8c6336d B1
  3. d802048 B
  4. 41345d2 A
  5.  

And if you did disable the reflog
(since I do have a reflog, I need to add a param to ignore it)
Code: Text  [Select][+][-]
  1. git fsck --no-reflogs
  2. Checking object directories: 100% (256/256), done.
  3. dangling commit 8c6336db21a6e8a9a7e174941697d9265a5696d1
  4.  
  5. git log --oneline 8c6336db21a6e8a9a7e174941697d9265a5696d1
  6. 8c6336d B1
  7. d802048 B
  8. 41345d2 A
  9.  
There is often much more output, but you do look for "dangling commit"


So your example "double click a different branch"
Whatever it does... With the above methods you should be able to get back.

And while - as I said - I don't know Sourcetree, I find it most curious that a double click should have such an effect.
Have you tried "git branch" from the command line, to see if the old branch is still in the list? (or "git reflog", which will show you what HEAD was previously at).
Maybe Sourcetree is hiding it....


"rebasing"
Well SVN doesn't have it, so you can't run into issues.
I guess you did not finish the rebase, but also not abort it. And so new commits where made as addition to the rebase. If you then later cancelled the rebase, then the new commits would be "gone" => but not lost.

What actually goes is the temporary branch, on which the rebase was build. But the commits are still there (2 weeks without reflog, 6 weeks with reflog / both configurable).
And it's the same steps as above.

"git status" will tell you if any operation (rebase, bisect, ...) is ongoing.
Here a rebase with a current conflict:
Code: Text  [Select][+][-]
  1.  git status
  2. interactive rebase in progress; onto 230d446
  3. Last command done (1 command done):
  4.    edit 8c6336d B1
  5. No commands remaining.
  6. You are currently rebasing.
  7.   (fix conflicts and then run "git rebase --continue")
  8.   (use "git rebase --skip" to skip this patch)
  9.   (use "git rebase --abort" to check out the original branch)
  10.  
  11. Unmerged paths:
  12.   (use "git restore --staged <file>..." to unstage)
  13.   (use "git add <file>..." to mark resolution)
  14.         both modified:   file2
  15.  
  16. Untracked files:
  17.   (use "git add <file>..." to include in what will be committed)
  18.         file1.txt
  19.  
  20. no changes added to commit (use "git add" and/or "git commit -a")
  21.  

It tells you how to abort "git rebase --abort".

And before aborting you can create a new branch. You can stash (or commit (either on the new branch, or detached)) any changes in the worktree.

The biggest risk here is, if you make changes to the worktree (maybe not resolving but making a new feature), if you never commit then, but then use "git rebase --abort" -> because that will ignore the working tree changes and switch to the branch you had been on before the rebase.
So effectively "git rebase --abort" is a way to throw away the current uncommitted worktree.

So if you haven't committed your changes, there are ways to do damage.
But when you do "git rebase --abort" git can't know if changes in the worktree where your attempt to resolve conflicts, and you are giving up, hence no longer needing them...
Or if you 1) forgot that you were still rebasing, 2) added new changes 3) did forget to commit (which you could have, even in a rebase) 4) now realized you were in a rebase....


Btw "git switch -f" will also override a modified worktree.
The -f (force) is like adding an "svn revert".




And well yes, if you are new to git, you don't know any of those commands.

But, you likely have internet. You can ask. Likely find the steps on stackoverflow or similar....

And those steps still work, even if you did further commits. So if you don't have the answer immediately you still haven't lost anything.
(except if you do stuff like "git prune --expire now")

PascalDragon

  • Hero Member
  • *****
  • Posts: 4562
  • Compiler Developer
Re: How to revert my mess (repository)
« Reply #13 on: July 14, 2022, 08:57:06 am »
I sometimes use Git from the command-line (with a bit of Googling). That tends to work. I used Tortoise Git in the past for a bit, with good results, although sometimes it was a bit confusing. Now I use Sourcetree, and it happened multiple times that I lost my work. Easiest way: double click a different branch. A bit harder: forget to make a branch up front. And I had it once with rebasing, but I don't do that very often. And of course, merging can be a pain, but that has nothing to do with Git.

I only use the command line (no matter if on Windows or Linux), so I can be sure that if something does get messed up its my own fault. :P

 

TinyPortal © 2005-2018