How does adding files to .gitignore affect existing tracked files in Git?
- Tracked files are immediately untracked and removed from the repository.
- Tracked files remain, but changes to them are no longer tracked.
- Tracked files are ignored only for the current commit.
- Tracked files are deleted from the working directory, but not the repository.
When files are added to .gitignore, it only affects untracked files. Existing tracked files remain in the repository, and their changes are still tracked unless committed before the addition to .gitignore.
What is the process for recovering a Git repository if the .git directory is accidentally deleted or corrupted?
- git recover
- git restore
- git clone
- git init
The correct process is to use git clone to create a new copy of the repository from a remote or another existing repository. This will recover the repository, including its history and branches.
A development team is implementing a code quality tool into their Git workflow. They need to automatically reject commits that don't meet the quality standards. Which Git feature should they leverage?
- Git Hooks
- Git Stash
- Git Bisect
- Git Reflog
Git Hooks are scripts triggered by Git events, allowing the team to enforce code quality standards by rejecting commits that don't meet criteria.
What is the first step you should take when encountering a merge conflict in Git?
- Stash changes and reset to the last commit
- Manually resolve the conflict in the code
- Abandon changes made since the last commit
- Commit the changes without resolving the conflict
When encountering a merge conflict in Git, the first step is to manually resolve the conflict in the code. This involves identifying and resolving the conflicting changes in the affected files. Stashing changes, resetting to the last commit, or committing without resolving the conflict are not recommended as they may lead to issues in the version history and code consistency.
The git ______ command is used to switch branches or restore working tree files.
- checkout
- switch
- restore
- branch
The correct option is "checkout." The git checkout command in Git is versatile and can be used for various purposes, including switching branches and restoring working tree files. For example, git checkout switches to the specified branch.
How can you view the changes introduced in a specific commit using Git?
- git show
- git diff
- git log -p
- git log --oneline
To view the changes introduced in a specific commit, you can use git show . This command displays the details of the commit, including the changes made.
What is a Git hook?
- A script that runs before or after events
- A branch in Git
- A Git repository
- A command to undo the last commit
A Git hook is a script that runs automatically before or after certain Git events, such as committing or merging. It allows developers to customize and automate processes in response to specific actions in the Git workflow.
After performing a rebase, you may need to use git ______ to incorporate the changes into the base branch.
- apply
- merge
- commit
- pull
After performing a rebase, you can use git apply to incorporate the changes into the base branch. This step is necessary to complete the rebase process and update the branch with the rebased changes.
How can branching strategies in Git enhance build automation processes?
- By using feature branches
- By adopting a GitFlow workflow
- By creating release branches
- By following a linear development approach
In Git, branching strategies like GitFlow can enhance build automation by providing a structured approach to managing feature development, releases, and hotfixes. GitFlow specifically defines branches such as feature branches for new features and release branches for stable releases, streamlining the build process.
If a branch history is corrupted, one can use git _______ to recreate commits from the reflog.
- git restore
- git reflog
- git recover
- git recreate
The correct option is git reflog. This command is used to access the Git reflog and can be helpful in recovering from a corrupted branch history by allowing the recreation of commits from the reflog.