49) In Git how do you revert a commit that has already been pushed and made public? There can be two answers to this question and make sure that you include both because any of the below options can be used depending on the situation: Remove or fix the bad file in a new commit and push it to the remote repository. This is the most natural way to fix an error. Once you have made necessary changes to the file, commit it to the remote repository for that I will use git commit -m “commit message”. Create a new commit that undoes all changes that were made in the bad commit.to do this I will use a command git revert 50) What is the difference between git pull and git fetch? Git pull command pulls new changes or commits from a particular branch from your central repository and updates your target branch in your local repository. Git fetch is also used for the same purpose but it works in a slightly different way. When you perform a git fetch, it pulls all new commits from the desired branch and stores it in a new branch in your local repository. If you want to reflect these changes in your target branch, git fetch must be followed with a git merge. Your target branch will only be updated after merging the target branch and fetched branch. Just to make it easy for you, remember the equation below: Git pull = git fetch + git merge 51) How do you find a list of files that has changed in a particular commit? git diff-tree -r {hash} Given the commit hash, this will list all the files that were changed or added in that commit. The -r flag makes the command list individual files, rather than collapsing them into root directory names only. The output will also include some extra information, which can be easily suppressed by including a couple of flags: git diff-tree --no-commit-id --name-only -r {hash} Here --no-commit-id will supress the commit hashes from appearing in the output, and -- name-only will only print the file names, instead of their paths.

49) In Git how do you revert a commit that has already been pushed and made
public?
 There can be two answers to this question and make sure that you include both
because any of the below options can be used depending on the situation:
 Remove or fix the bad file in a new commit and push it to the remote repository. This
is the most natural way to fix an error. Once you have made necessary changes to the file, commit it
to the remote repository for that I will use
git commit -m “commit message”.
 Create a new commit that undoes all changes that were made in the bad commit.to
do this I will use a command
 git revert <name of bad commit>
50) What is the difference between git pull and git fetch?
 Git pull command pulls new changes or commits from a particular branch from your
central repository and updates your target branch in your local repository.
 Git fetch is also used for the same purpose but it works in a slightly different way.
When you perform a git fetch, it pulls all new commits from the desired branch and stores it in a new
branch in your local repository. If you want to reflect these changes in your target branch, git fetch
must be followed with a git merge. Your target branch will only be updated after merging the target
branch and fetched branch. Just to make it easy for you, remember the equation below:
 Git pull = git fetch + git merge
51) How do you find a list of files that has changed in a particular commit?
 git diff-tree -r {hash}
 Given the commit hash, this will list all the files that were changed or added in that
commit. The -r flag makes the command list individual files, rather than collapsing them into root
directory names only.
 The output will also include some extra information, which can be easily suppressed by
including a
couple of flags:
 git diff-tree --no-commit-id --name-only -r {hash}
 Here --no-commit-id will supress the commit hashes from appearing in the output, and --
name-only will only print the file names, instead of their paths.

Comments