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.
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.
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.
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 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.
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.
In the context of large-scale collaborative projects, what is a key advantage of using the Forking workflow over Gitflow?
- Better support for feature branching
- Simplicity and ease of use
- Enhanced collaboration and code review capabilities
- Strict control over the repository
The Forking workflow allows for a more decentralized and parallel development approach. Each contributor works in their own fork, making it easier to manage contributions and conduct code reviews before merging changes. This can be advantageous in large, distributed teams where collaboration is crucial.
Which Git feature is essential for managing large-scale projects in an enterprise environment?
- Git Submodules
- Git Hooks
- Git LFS (Large File Storage)
- Git Stash
Git LFS is crucial for managing large-scale projects in an enterprise environment. It allows efficient handling of large binary files by storing them outside the regular Git repository, preventing repository bloat and improving performance.
A developer is working on a feature that is based on an outdated main branch. What strategy should they use to update their branch with the latest changes from the main branch?
- git fetch origin main && git merge origin/main
- git pull origin main
- git rebase origin/main
- git branch update && git merge update
When working on an outdated branch, using git pull origin main is recommended. This fetches the latest changes and automatically merges them into the developer's branch. Using git fetch and git merge separately provides more control over the process. Options 1 and 3 are correct commands but combined in a way that might lead to unnecessary complications. Option 4 does not follow the typical Git workflow.
How does git stash pop differ from git stash apply?
- git stash pop removes the latest stash and applies it, while git stash apply leaves the stash in the stack.
- git stash pop and git stash apply are interchangeable; there is no difference between them.
- git stash pop is used for temporary stashing, while git stash apply is for permanent stashing.
- git stash pop is for applying stashes in a specific order, while git stash apply applies the most recent stash.
In-depth git stash pop is a combination of git stash apply and git stash drop, which removes the stash from the stack after applying it.
What advanced technique can be used in Git to combine multiple commit histories into a single unified history?
- Git rebase
- Git merge
- Git cherry-pick
- Git reset
The advanced technique in Git to combine multiple commit histories into a single unified history is 'Git rebase.' It allows you to reapply commits on top of another branch, resulting in a cleaner and more linear commit history. This can be useful in creating a streamlined and comprehensible project history.
A large enterprise is migrating to Git. They are concerned about preserving their extensive development history. Which Git feature should they focus on?
- Git Tags
- Git Stash
- Git Reflog
- Git Submodules
The Git Reflog is a crucial feature that allows the enterprise to track changes and easily recover any lost commits during the migration process. It maintains a log of all committed changes, providing a safety net for preserving development history.