Git FAQs | Git Interview questions

what is the command to view all the commits made by a specific person?

git log –author=’codedaily’

What is the git command to see all the commits since the date?

git log -–since=”2017-01-01″

What is the significance of using –index in the git stash pop index command?

To pull the staged changes from stack

How do I view all the commits for the last 2 weeks ?

git log -–since=”2 weeks ago”

What is the command to temporarily store uncommitted ?

git stash

What is the git command to see the last 3 commits in one line ?

git log -–oneline -3

I want to take all the changes I made in the staging to my working directory , what command should I use to do this operation ?

git reset HEAD

What is the output of the command git reset -–soft HEAD ~5 ?

move the last 5 commits as 1 into the staging area

What is the GIT command to see all the remote branches?

To see local branches, run this commandgit branch.
To see remote branches, run this commandgit branch -r.
To see all local and remote branches, run this commandgit branch -a.

Which Command is used to show limited number of commits?

git log -n 
The command is used to show a limited number of commits.

Which command defines the author email to be used for all commits by the current user?

git config --global user.email

What does the Git clone command does?

A. Makes a local copy of the repository
B. Creates a working directory

Git command to compare two specified branches

git diff

what’s git command to switch branch?

git checkout <existing_branch>
git checkout -b <new_branch>

Compare specific file between two branches?

git diff master..feature -- <file>

Remove a file from git without removing it from your file system?

If you have added any files by mistake up adding files that you didn’t want to commit. In that case, make sure you only remove the staged version and add the file to your .gitignore to avoid making the same mistake a second time.

git reset filename # or git remove --cached filename
echo filename >> .gitignore # add it to .gitignore to avoid re-adding it

How to edit a commit message?

Typos happen, but luckily in the case of commit messages, it is very easy to fix them. In case you have not pushed commit to server you can use below command
git commit --amend # start $EDITOR to edit the message
git commit --amend -m "New message" # set the new message directly

In case you have pushed commit to server already you may need to force push.
git push –force