252 viewsAsked at 2 companies
How to revert the last two commits but keep their changes?
AI answer
In Git, there are several commands to undo changes depending on the situation:
git checkout -- <file>— undo changes in the working directory for a specific file, reverting it to the last commit state.git reset HEAD <file>— remove the file from the index (staging area), but keep the changes in the working directory.git reset --hard— revert all changes in the working directory and index to the last commit (all unsaved changes will be lost).git revert <commit>— create a new commit that undoes the changes of the specified commit.
Example of undoing all local changes:
git reset --hard
Be cautious with this command, as it permanently deletes unsaved changes.
Also asked at СБЕР Авто
- How to implement communication between two goroutines in Go?
- Do you have a military ID or a registration card in hand?
- Tell me about the team: what roles are there, how do you interact?
- How to limit the number of goroutines so that no more than 'threads' methods of Process run simultaneously? Who will be pulling tasks from the channel?
- What value is stored in a slice if it was defined but not explicitly initialized?
Similar questions
- Which command can change the base commit from which the current branch starts?
- How can changes be rolled back within a single transaction?
- What is the difference between the merge and rebase commands?
- If you run git add only for some of the changed files, what exactly will be included in the commit when you run git commit -m? Files specified in git add, entirely with their current state, including unstaged changes All changes in all modified files, even those not added to the index Only the most recently modified files from the working directory Only the changes added to the index
- Could you explain what is meant by the operation 'commit' in version control systems?