How to roll back a project to GitHub version? The project is on GitHub, I made changes on my computer and did not even commit, after I realized that I don’t do better than these changes and I want to return everything as it was at the time of the last commit.git fetch , git pull tried, git clone also tried, it's not that.
- git revert --continue tried? But in general, it is strange that git clone did not help you, because there is created a new folder with source codes that are located remotely. - Komdosh
- in order to use git revert, I suppose you have to commit first, and then roll it back? - Aleksandr Sergeevich
- git clone copies only those files that are on the git Hub, and I still have a part of the ignore on my computer, in the end after the git clone some of the files were missing - Aleksandr Sergeevich
- Damn, yes, in general, I got confused and turned out to be wrong, in Intellij IDEA there is a revert, which allows you to roll back files to the state of a commit, so it’s useful to search for it in the gita. The answer with reset --hard is correct. Regarding clone, I thought you were trying to clone to another folder. - Komdosh
- I advise you to use GitExtension. It is more convenient than the classic Git GUI. - adrug
5 answers
Use reset:
git reset --hard @{u} - There was no commit, the branch did not go anywhere, reset nowhere to do - Komdosh
- This option is also working - DiDex
- 2The author did not say that he created a new branch. Judging by this, it is in the master, and the reset will be made before the master's commit commit. - Grulex
- Ah, well, yes, yes, I agree - Komdosh
- one"The author did not say that he created a new branch," but he did not say that he had not created it. Usually new changes are not done in master. - simpleCode
I in such cases do git reset --hard HEAD - this is practically the same as the answer git reset --hard HEAD .
You don’t delete existing files that git doesn’t know about in this way , but there’s no way, unless you delete those files yourself . (@ D-side suggests that you can use the git clean -df - deletes all files in the folder that are not related to the project and are not stored in the repository)
Alternatively, you can pick up the changes in your pocket and immediately empty it:
git stash git stash drop - one"there is no way at all, unless you delete these files yourself" - which, by the way, does
git clean(with certain flags). - D-side - @ D-side By the way, it turns out that if some of the files in .gitignore and, respectively, do not participate in version control, then
git clean -dfwill not erase them accidentally, right? I understand the-dfshould not allow it to overdo it, or did I misunderstand? - Aleksandr Sergeevich - @AleksandrSergeevich "do not overdo it" says the lack of options among the
x(which just says "and do not look at Giginor"). And in general, there is an instruction :) - D-side - one"it's almost the same" - not quite . Therefore, in my opinion, this answer is more correct and complete. Instead of HEAD, @ is better, the 3rd characters are shorter. - simpleCode
try git reset - mixed with an indication of a branch, your addition should be canceled without a commit
- 2git reset - mixed like does not touch the working copy in principle? It seems that this is absolutely not what the author needs ... - Pavel Mayorov
- it seems like the author and not commit, I suppose we are talking about a local repository, which he just wants to cancel the additions and does not want to stumble on conflicts. In this case, if you don’t want to dance with a tambourine, you can delete the entire repository from the locale and incline it again :) - Reason
Try using git checkout [имя файла] , read more here.
- checkout will not return files to the status from the server - Komdosh
- 2Yes, it will not, but why take it from the server, if it is in the folder .git - DiDex
- Oh, yes, but still, if there was no commit, then the files that were currently changed will not return the commit to the previous state, revert is needed - Komdosh
- one@PavelMayorov, reset returns the same branch to the commit, and as far as I understand it, you need to stupidly roll back the current changes - Komdosh
- oneif a lot of files have changed, then you get tired of doing a checkout for everyone, so the option is so-so. - AK ♦
Decision:
I see in the question that you did not commit, if you also did not add the modified files to the index with the git add command, you can use the command:
git checkout -- . This command rolls back the modified files to their original state, i.e. when there was absolutely no change.
Theory:
Where does Git find out which branch you're on at the moment? It stores a special pointer called HEAD.
git reset - updates the index by moving it to HEAD.
git checkout - updates the work branch. HEAD will be updated in case you make the transition from branch to branch.
The main thing:
You need to understand what you want to receive after entering the command. Described in more detail here - link to the article .