Revert a commit on GitLab

Clement -  
NHenry Posted messages 2511 Registration date   Status Modérateur Last intervention   -
Hello,

I hope my question will be clear and understandable, I've only been using GitLab for a short time.

Yesterday, I wanted to upload a file to a GitLab server that others also have access to. It worked, but all the files that were on the "master" branch disappeared once I added my file. The history of the master branch indicates that my commit deleted all those files.

I wanted to undo this action by trying to find all those files elsewhere, downloading them, and putting them in my git folder, then doing git push to put them back on the server in question. It worked, but there are a lot of files that I couldn’t manage to find.

Today, someone made a commit to add some files.

So I have 2 questions: is it possible to undo my 2 commits without touching the commit made by that last person? Basically, to make sure my actions have no impact?

I've heard about a command git revert --no-commit XX..HEAD git commit
Could that work?

2nd question: how come the other files disappeared when I simply added one file?

Thank you very much..

2 réponses

NHenry Posted messages 2511 Registration date   Status Modérateur Last intervention   387
 
At worst, you can create a branch from the last commit (git branch ...)
Then force the master branch to the last good commit. (Git reset <Hash>)
Try to recreate the commits correctly
and push everything with git push --force

--
I mainly work in VB6 and VB.NET, with a bit of C#, but moderation often leads me to other languages.
In VB.NET, remember to enable "Option Explicit" and "Option Strict"
0
Clement
 
Thank you for your advice.
Could you quickly explain to me how it is that the commands I entered:

git pull / git add . / git commit -a -m “my comment” / git push

ended up deleting the files from the master branch when I actually wanted to add a file, not delete one.

As I mentioned, I'm a newbie to GitLab, but could it be because the GitLab folder on my PC didn’t contain any of the files from the server, so when I entered my command, the server synchronized with my GitLab folder, and thus everything disappeared?

And if so, does this mean that for my future uploads, I will need to have all the files from the server present in my GitLab folder each time to avoid the same problem occurring?

And one last question, when I looked over the list of files that I deleted, and when I click on their names on the server, I can still access, download some of them, etc. Isn't that strange, given that I’m supposed to have deleted them?
0
NHenry Posted messages 2511 Registration date   Status Modérateur Last intervention   387 > Clement
 
git commit -a :
-a, --all
Indique à la commande de mettre automatiquement en scène les fichiers qui ont été modifiés et supprimés, mais les nouveaux fichiers que vous n'avez pas signalés à Git ne sont pas affectés.

En gros, mettre un -a valide automatiquement tous les fichiers modifiés et supprimés.
Je te recommande de l'éviter et de faire les "git add" de chaque fichier modifié, cela te permettra d'éviter de pousser des modifications non désirées.
"Git add ." fait déjà les ajouts et les modifications (mais pas les suppressions)

De base, il est recommandé d'avoir tous les fichiers du commit sur lequel tu es. Tu pourras faire des choses plus pointues plus tard avec l'expérience. Git est très puissant, mais une grande puissance requiert une grande responsabilité.

Gitlab est un serveur de dépôt pour git, tout comme l'est github, gitea, ...

Git enregistre tout, les fichiers supprimés ne le sont que sur les commits que tu as poussés, les commits précédents ne sont pas changés.
0
Clement
 
Thank you very much!
0
NHenry Posted messages 2511 Registration date   Status Modérateur Last intervention   387
 
If the issue is resolved, please click on "Mark as resolved".
0