One of my client have a local folder, previously connected with an on-line repository, where inside I did many modifications to files and folders. Later they said that these were not important anymore but the decision was reversed. Anyway along the process I decided to push everything to the on-line repository.
Before starting the process, I used the following commands where I lost replies (I've not reported before just because there were some credential errors in connection with the remote repository so I considered not important) from terminal now. This will help to understand what happened later with the listed operations through the terminal:
$git add -A
$git commit -m 'aggiornamento'
$git push
$git push Documenti
$git push -u origin master
$git remote add origin https://ereng@bitbucket.org/Documenti
$git push --set-upstream origin master
$git remote add origin https://ereng@bitbucket.org/ereng/documenti
$git push
$git push --set-upstream origin master
$git remote add origin https://ereng@bitbucket.org/ereng/documenti
$git remote set-url https://ereng@bitbucket.org/ereng/documenti
$git remote set-url origin https://ereng@bitbucket.org/ereng/documenti
$git push --set-upstream origin master
$git status
$export LANG="en_US.UTF-8"
Using directly the push command, it replied that the versions were different so I have to manage differently:
git push --set-upstream origin master
Password for 'https://ereng@bitbucket.org':
To https://bitbucket.org/ereng/documenti
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://bitbucket.org/ereng/documenti'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
(base) zed@sdCmpns:~/Documenti$ git fetch origin master:tmp
Password for 'https://ereng@bitbucket.org':
warning: no common commits
remote: Enumerating objects: 1957, done.
remote: Counting objects: 100% (1957/1957), done.
remote: Compressing objects: 100% (1511/1511), done.
remote: Total 1957 (delta 495), reused 1676 (delta 424), pack-reused 0
Receiving objects: 100% (1957/1957), 424.00 MiB | 21.59 MiB/s, done.
Resolving deltas: 100% (495/495), done.
From https://bitbucket.org/ereng/documenti
* [new branch] master -> tmp
* [new branch] master -> origin/master
(base) zed@sdCmpns:~/Documenti$ git rebase tmp
warning: Cannot merge binary files: GLF/Lbrtt (HEAD vs. b13cdfa (I invio da SD Cmpns))
Auto-merging GLF/Lbrtt
CONFLICT (add/add): Merge conflict in GLF/Lbrtt
error: could not apply b13cdfa... I invio da SD Cmpns
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply b13cdfa... I invio da SD Cmpns
(base) zed@sdCmpns:~/Documenti$ git push origin HEAD:master
Password for 'https://ereng@bitbucket.org':
Everything up-to-date
(base) zed@sdCmpns:~/Documenti$ git push
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use
git push origin HEAD:<name-of-remote-branch>
(base) zed@sdCmpns:~/Documenti$ git branch -D tmp
Deleted branch tmp (was 231205b).
(base) zed@sdCmpns:~/Documenti$ git add -A
(base) zed@sdCmpns:~/Documenti$ git commit -m 'aggiornamento prima di partire per XrtgllX'
[detached HEAD a810646] aggiornamento prima di partire per XrtgllX
37 files changed, 440601 insertions(+)
create mode 100644 .~lock.Record-online-voice-recorder.docx#
create mode 100644 FYSC/2019/Dichiarazione2020_GHNBGH86LmOO_20061746441997398.pdf
create mode 100644 FYSC/2019/INFORMATIVA IMU 2019.pdf
create mode 100644 FYSC/2020/MRTSNR94M11A285F_F24-Redditi.pdf
create mode 100644 FYSC/2020/Dichiarazione2021PF_GHNBGH86LmOO_21061635090490934.pdf
create mode 100644 FYSC/2020/elaborazionegnidAccount/.~lock.RT 2019 Mich.pdf#
create mode 100644 FYSC/2020/elaborazionegnidAccount/RM 2018 Mich.pdf
create mode 100644 FYSC/2020/elaborazionegnidAccount/RM 2019 Mich.pdf
create mode 100644 FYSC/2020/elaborazionegnidAccount/RM 2020 Mich.pdf
create mode 100644 FYSC/2020/elaborazionegnidAccount/RM 2020 Mich_FT.pdf
create mode 100644 FYSC/2020/elaborazionegnidAccount/RT 2018 Mich.pdf
create mode 100644 FYSC/2020/elaborazionegnidAccount/RT 2020 Mich.pdf
create mode 100644 FYSC/2020/elaborazionegnidAccount/RW 2018 Mich.pdf
create mode 100644 FYSC/2020/elaborazionegnidAccount/RW 2019 Mich.pdf
create mode 100644 FYSC/2020/elaborazionegnidAccount/RW 2020 Mich.pdf
create mode 100644 FreeCAD/00-AECX-SKL2-Spreader.STEP
create mode 100644 ManagerONNI/CV.pdf
create mode 100644 ManagerONNI/Domanda di Iscrizione.pdf
create mode 100644 ManagerONNI/doctrt.pdf
create mode 100644 "ManagerONNI/identit\303\240.pdf"
create mode 100644 ManagerONNI/iscri_ordine.pdf
create mode 100644 ManagerONNI/lreaL3.pdf
create mode 100644 ManagerONNI/lreaLS.pdf
create mode 100644 ManagerONNI/linguaIngleseTOEFL.pdf
create mode 100644 ManagerONNI/ricevutaBonifico.pdf
create mode 100644 NDAfornitori-MOCOM.pdf
create mode 100644 Record-online-voice-recorder.docx
create mode 100644 Statements.odt
create mode 100644 VISURA_08301650720-VISUORD.pdf
create mode 100644 toqIMU2019/toq Comune IMU.pdf
create mode 100644 toqIMU2019/contratto locazione 2011.pdf
create mode 100644 toqIMU2019/contrattoLoc2014.pdf
create mode 100644 display.pdf
create mode 100644 pergamena lrea e doctrt.pdf
create mode 100644 preventivopiattaforma.pdf
create mode 100644 si.pdf
create mode 100644 untitled_1.ods
(base) zed@sdCmpns:~/Documenti$ git push
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use
git push origin HEAD:<name-of-remote-branch>
(base) zed@sdCmpns:~/Documenti$ git push origin HEAD:master
Password for 'https://ereng@bitbucket.org':
Enumerating objects: 48, done.
Counting objects: 100% (48/48), done.
Delta compression using up to 16 threads
Compressing objects: 100% (46/46), done.
Writing objects: 100% (46/46), 42.95 MiB | 6.00 MiB/s, done.
Total 46 (delta 6), reused 0 (delta 0), pack-reused 0
To https://bitbucket.org/ereng/documenti
231205b..a810646 HEAD -> master
(base) zed@sdCmpns:~/Documenti$ git log GLF/Lbrtt
commit 231205b93608f834ba0ac64c90c4b672b63915d3
Author: erengpoliba <oiveras@libero.it>
Date: Sat Aug 3 10:44:57 2019 +0200
aggiornamento
commit 19d9a59c21cedd5cc49c0c2f598b3ccf6b4213f7
Author: erengpoliba <oiveras@libero.it>
Date: Wed Aug 22 17:15:32 2018 +0200
aggiornamenti incompleti agosto
commit ec6703753f782af2ab6f12f1c06441c59d331eab
Author: erengpoliba <oiveras@libero.it>
Date: Mon Sep 25 09:07:16 2017 +0200
aggiornamento soldi
commit 13e8be02f614ec74b180bb7633c4af0f9622f0e5
Author: erengpoliba <oiveras@libero.it>
Date: Mon Aug 28 12:20:02 2017 +0200
aggiornamento dopo estate
:
The problem now is that all the files are at the version on the online repository. And I want to recover all the files as they were locally modified. How to get back? Important is not only to get back all the files but also I need to recover the file GLF/Lbrtt that got a conflict.
The purpose now is the following:
How to get this?
Right now, I got this:
$ git reflog
a810646 (HEAD, origin/master) HEAD@{0}: commit: aggiornamento prima di partire per XrtgllX
231205b HEAD@{1}: rebase (start): checkout tmp
4954892 (master) HEAD@{2}: commit: aggiornamento
b13cdfa HEAD@{3}: commit (initial): I invio da SD Cmpns
I think the version I want back is '4954892' (the one I had on the local folder). I don't know how to check the date, but it is one version that is not on the remote repository, so I think it's the right one. How to do that?
I solved in the following ways. I used the commands:
git status #to know the situation in a specific branch (not the one to solve)
git reflog #to get information on the last commits also on other branches in my local folder
git branch -a #to know all the branches in the repository
So when clear that my local repository was in another branch (different where I commited the modifications I wanted) I did the following:
git checkout master #the branch where I commited the last files I wanted
git checkout 4954892 #to have the file where I wanted
Checked that my files were all recovered, I made some modifications, then commited again with:
git add -A
git commit -m 'recovered and corrected'
Then I created a new repository remotely:
git branch -u origin/newbranch
and I pushed everything on the new branch, then I merged:
git push
git merge newbranch --allow-unrelated-histories
So I reached the goal. Obviously I needed to move to the right branch to apply the specific operations before applying the commands