0% found this document useful (0 votes)
13 views15 pages

Git Possible Viva Ques

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views15 pages

Git Possible Viva Ques

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Here are the answers for questions 8 to 12, continuing from where we left off:

Here is a structured list of the Git lab questions along with the answers:

1. Setting Up and Basic Commands


1.
What does the command 'git init' do?

It initializes a new Git repository in the current directory.

2.
How do you add a new file to the staging area?

Use the command git add <filename> to add a file to the staging area.

3.
What is the purpose of a commit in Git?

A commit captures a snapshot of the changes in the repository, marking a point in history.
4.
How can you check the status of your repository?

Use the command git status to check the status of the working directory and staging area.

5.
What is a commit message and why is it important?

A commit message is a description of the changes made in that commit. It is important for understanding the history of the project.

2. Creating and Managing Branches


1.
How do you create a new branch in Git?

Use the command git branch <branch-name> to create a new branch.

2.
What is the difference between the 'master' and 'feature' branches?

'master' is the default branch, often used for production code, while 'feature' branches are used for developing new features or changes.
3.
What happens when you merge a branch into another?

The changes from one branch are integrated into the target branch.

4.
How can you switch between branches?

Use the command git checkout <branch-name> to switch branches.

5.
What is the significance of the 'git merge' command?

It integrates the changes from one branch into another, typically from a feature branch into the master branch.

3. Stashing Changes
1.
What does 'git stash' do?

It temporarily saves changes that are not yet committed, allowing you to work on something else without committing unfinished changes.

2.
How can you apply stashed changes?

Use git stash apply to apply the most recent stash, or git stash apply <stash-id> to apply a specific stash.

3.
How do you list all the stashed changes?

Use the command git stash list to view all stashes.

4.
Can you delete a stash after applying it?

Yes, use git stash drop <stash-id> to delete a specific stash, or git stash clear to delete all stashes.

5.
What is the difference between 'git stash' and 'git commit'?

git stash saves changes temporarily without committing, while git commit saves changes permanently to the repository.

4. Collaboration and Remote Repositories


1.
What is the purpose of 'git clone'?
It copies a remote repository to your local machine, including all files, commits, and branches.

2.
How do you fetch changes from a remote repository?

Use git fetch to download new data from a remote repository without making any changes to your local repository.

3.
What is the difference between 'git fetch' and 'git pull'?

git fetch retrieves changes from a remote repository but does not merge them, while git pull fetches and automatically merges the
changes.

4.
What does 'git push' do?

It uploads your local commits to a remote repository.

5.
How do you set up a remote repository in Git?

Use git remote add <name> <url> to add a remote repository, where <name> is the alias for the remote and <url> is the repository URL.
5. Merging with Custom Commit Message
1.
How do you merge two branches in Git?

Use the command git merge <branch-name> to merge the specified branch into the current branch.

2.
What is a custom commit message and how do you add it?

A custom commit message describes the changes made during a merge. It can be added using the --message flag: git merge <branch-
name> --message "Custom message".

3.
What happens when a merge conflict occurs?

Git cannot automatically merge the branches due to conflicting changes, and manual resolution is required.

4.
How can you resolve a merge conflict in Git?

Edit the conflicting files to resolve the issues, then add and commit the changes.

5.
What is the 'git merge --no-ff' option used for?
It ensures that a merge commit is created, even if the merge could be resolved with a fast-forward merge.

6. Git Tags and Releases


1.
What is a Git tag?

A tag in Git is a reference to a specific point in Git history, often used for marking release versions.

2.
How do you create a lightweight tag?

Use the command git tag <tag-name> to create a lightweight tag.

3.
What is the difference between lightweight and annotated tags?

A lightweight tag is simply a pointer to a commit, while an annotated tag contains metadata like the tagger’s name, email, and date.

4.
How do you list all tags in your repository?

Use the command git tag to list all tags in the repository.
5.
Why are tags important in Git?

Tags are used to mark important points in the repository’s history, such as releases.

7. Advanced Git Operations


1.
What is cherry-picking in Git?

Cherry-picking is the process of applying a specific commit from one branch to another.

2.
How do you cherry-pick multiple commits?

Use the command git cherry-pick <commit-id1> <commit-id2> to cherry-pick multiple commits.

3.
How do you resolve conflicts during cherry-picking?

Manually resolve the conflicts in the files, then stage and commit the changes.
4.
What is the difference between 'git merge' and 'git cherry-pick'?

git merge combines changes from one branch into another, while git cherry-pick applies a specific commit to another branch.

5.
What happens if you cherry-pick a commit that has already been applied?

Git will attempt to apply the commit again, possibly resulting in a conflict or a redundant commit.

8. Analyzing and Changing Git History


1.
How do you view the details of a specific commit?

Use the command git show <commit-id> to view details about a commit.

2.
What command shows all commits by a specific author?

Use git log --author="Author Name" to filter commits by a specific author.

3.
How can you view the last 5 commits in Git?

Use git log -n 5 to display the last 5 commits.

4.
How do you undo a commit in Git?

Use git revert <commit-id> to create a new commit that undoes the changes.

5.
What is the purpose of 'git revert' and how is it used?

git revert creates a new commit that reverses the changes of a specified commit without altering the commit history.

9. Analyzing and Changing Git History


1.
How do you view the details of a specific commit?

Use the command git show <commit-id> to view details of a specific commit, including the author, date, and commit message.
2.
What command shows all commits by a specific author?

Use git log --author="Author Name" to filter and display all commits made by a specific author.

3.
How can you view the last 5 commits in Git?

Use the command git log -n 5 to display the last five commits made in the repository.

4.
How do you undo the changes introduced by a commit with the ID "abc123"?

Use git revert abc123 to create a new commit that undoes the changes introduced by commit abc123.

5.
What is the purpose of 'git revert' and how is it used?

git revert is used to create a new commit that undoes the changes made by a previous commit, preserving the history of the repository.

10. Analysing and Changing Git History (Continued)


1.
Given a commit ID, how would you use Git to view the details of that specific commit, including the author, date, and commit message?

Use the command git show <commit-id> to display detailed information about a commit, including the author, date, and the commit
message.

2.
Write the command to list all commits made by the author "JohnDoe" between "2023-01-01" and "2023-12-31."

Use git log --author="JohnDoe" --since="2023-01-01" --until="2023-12-31" to list commits made by "JohnDoe" within the specified date
range.

3.
Write the command to display the last five commits in the repository's history.

Use git log -n 5 to show the last five commits.

4.
Write the command to undo the changes introduced by the commit with the ID "abc123."

Use git revert abc123 to create a new commit that undoes the changes from commit abc123.

5.
What is the difference between 'git reset' and 'git revert'?

git reset changes the state of the repository by removing commits from the history, whereas git revert creates a new commit that undoes
the changes of a previous commit, preserving history.
11. Analysing and Changing Git History
1.
Write the command to list all commits made by the author "JohnDoe" between "2023-01-01" and "2023-12-31."

Use git log --author="JohnDoe" --since="2023-01-01" --until="2023-12-31" to filter commits by the author within the specified time range.

2.
Write the command to display the last five commits in the repository's history.

Use git log -n 5 to show the last five commits.

3.
Write the command to undo the changes introduced by the commit with the ID "abc123."

Use git revert abc123 to revert the changes made by the commit abc123.

4.
How can you list all branches in a Git repository?

Use the command git branch to list all local branches, or git branch -a to list both local and remote branches.
5.
What is the purpose of the 'git log' command?

git log shows the commit history of a repository, including details like commit IDs, authors, dates, and commit messages.

12. Analysing and Changing Git History


1.
How do you undo the changes introduced by the commit with the ID "abc123"?

Use git revert abc123 to undo the changes of commit abc123 by creating a new commit that reverses its changes.

2.
Write the command to list all commits made by the author "JohnDoe" between "2023-01-01" and "2023-12-31."

Use git log --author="JohnDoe" --since="2023-01-01" --until="2023-12-31" to list all commits by "JohnDoe" in the specified date range.

3.
How do you display the last five commits in the repository’s history?

Use the command git log -n 5 to view the last five commits.

4.
What command can you use to view the changes introduced by a specific commit?

Use git show <commit-id> to see the changes made in a specific commit.

5.
How do you check for merge conflicts in Git?

Git automatically marks files with conflicts when you attempt to merge branches. Use git status to identify files with merge conflicts.

Feel free to use this list of questions and answers for your Git lab preparation! Let me know if you need further details or any clarification.

You might also like