Top 50 Git Interview Questions and Answers | Git Interview Preparation | DevOps Training | Edureka
You have accidentally deleted a branch. Is there any way to recover it and bring it back?
git reflog command, you are able to inspect all of the recent HEAD pointer movements in this repository. If the deletion hasnt been too long ago, you should be able to find the last commit on this branch. Using that commits SHA-1 hash, you are then able to recreate the branch.
In case you are using the Tower Git client, you can undo most actions simply by hitting CMD+Z. Heres how to restore a deleted branch:
How can you restore a previous version of your project?
git reset command is perfect for this task: you can provide the SHA-1 hash of the commit you want to return to and thereby restore the project to that revisions state.
43. Explain the difference between reverting and resetting.
31. Explain the different points when a merge can enter a conflicted stage.
There are two stages when a merge can enter a conflicted stage.
If there are changes in the working directory of the stage area in the current project, the merge will fail to start. In this case, conflicts happen due to pending changes that need to be stabilized using different Git commands.
The failure during the merge process indicates that thereâs a conflict between the local branch and the branch being merged. In this case, Git resolves as much as possible, but some things have to be fixed manually in the conflicted files.
How can you undo a commit that has already been pushed to a shared branch on a remote repository?
First of all, using
git push --force would not be a good solution in most cases. The reason for this is that force push has the potential to overwrite others work or at least change their commit history in an unexpected way.
A better, unobtrusive approach would be to use
git revert, because this will not rewrite / manipulate old commit history. Instead, a new commit will be created that corrects the effects of the unwanted one(s).
24. What do you understand about the Staging area in Git?
The Staging Area in Git is when it starts to track and save the changes that occur in files. These saved changes reflect in the .git directory. Staging is an intermediate area that helps to format and review commits before their completion.
16. Name a few Git commands and explain their usage.
Below are some basic Git commands:
||deletes the file from your working directory and stages the deletion.|
||list the version history for the current branch.|
||shows the metadata and content changes of the specified commit.|
||used to give tags to the specified commit.|
||used to switch from one branch to another.
creates a new branch and also switches to it.