Forum > Beginners

How to revert my mess (repository)

<< < (3/3)

SymbolicFrank:
@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:
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:

--- Quote from: SymbolicFrank on July 13, 2022, 04:42:09 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.

--- End quote ---

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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---git log --oneline230d446 (HEAD -> master) Cd802048 B41345d2 A git switch -d d802048HEAD is now at d802048 B echo 'ABC' > filegit commit -m B1  file[detached HEAD 8c6336d] B1 1 file changed, 1 insertion(+), 1 deletion(-) git log --oneline8c6336d (HEAD) B1d802048 B41345d2 A 
And now you accidentally

--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---git switch masterWarning: you are leaving 1 commit behind, not connected toany of your branches:   8c6336d B1 If you want to keep it by creating a new branch, this may be a good timeto do so with:  git branch <new-branch-name> 8c6336d Switched to branch 'master' 
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---git switch -d -HEAD is now at 8c6336d B1 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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---git reflog HEAD230d446 (HEAD -> master) HEAD@{0}: checkout: moving from 8c6336db21a6e8a9a7e174941697d9265a5696d1 to master8c6336d HEAD@{1}: commit: B1d802048 HEAD@{2}: checkout: moving from master to d802048230d446 (HEAD -> master) HEAD@{3}: commit: Cd802048 HEAD@{4}: commit: B41345d2 HEAD@{5}: commit (initial): A 
And (if you had made several detached commits) you can

--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---git log --oneline 8c6336d8c6336d B1d802048 B41345d2 A 
And if you did disable the reflog
(since I do have a reflog, I need to add a param to ignore it)

--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---git fsck --no-reflogsChecking object directories: 100% (256/256), done.dangling commit 8c6336db21a6e8a9a7e174941697d9265a5696d1 git log --oneline 8c6336db21a6e8a9a7e174941697d9265a5696d18c6336d B1d802048 B41345d2 A 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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- git statusinteractive rebase in progress; onto 230d446Last command done (1 command done):   edit 8c6336d B1No commands remaining.You are currently rebasing.  (fix conflicts and then run "git rebase --continue")  (use "git rebase --skip" to skip this patch)  (use "git rebase --abort" to check out the original branch) Unmerged paths:  (use "git restore --staged <file>..." to unstage)  (use "git add <file>..." to mark resolution)        both modified:   file2 Untracked files:  (use "git add <file>..." to include in what will be committed)        file1.txt no changes added to commit (use "git add" and/or "git commit -a") 
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:

--- Quote from: SymbolicFrank on July 13, 2022, 04:42:09 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. And of course, merging can be a pain, but that has nothing to do with Git.

--- End quote ---

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

Navigation

[0] Message Index

[*] Previous page

Go to full version