Today's Question:  What does your personal desk look like?        GIVE A SHOUT

Useful git commands in daily work

  sonic0002        2022-05-01 03:17:15       1,483        0    

In a developer's daily work, it is frequent to see lots of commits made. It would be a headache if one cannot use git commands well especially when in cases where some fixes need to be made on existing branches. There are some frequently used command such as git pull, git merge and git push. Apart from these, there are some other practical commands which may be useful for real use cases. This post will try to list some of them.

git grep 

It will lists all files containing the searched keyword. This is similar to the Linux command grep.

git blame

It will list the author and change time of each line in a specified file. This is pretty useful when wanna find who made the change and can approach to if there is anything to clarify or "blame".

git rm

Remove files from git, if wanna remove ignored files which have been mistakenly added but later are added to .gitignore. To stop tracking these ignored files, need to clean the cache.

git rm -r --cached [folder]

This will clear the folder specified. For example, if you added .idea folder into the commit and later realize it shouldn't be added, and you updated the .gitignore file to ignore this folder, you should also run above command to clear the cache otherwise it would still be there.

git log

When wanna check how many commits have been made by someone, can use git log command like below.

git log --author=[author] --oneline --color=never | wc -l
git log --author=[author] --oneline --color=never --since="since last week" | wc -l

This is useful when wanna do statistic report for the commits made within the team or department. (DO NOT RELY ON THIS TO EVALUATE PERFORMANCE THOUGH).

git checkout

Sometimes if wanna check some files from some previous commit to recover some of the mistakenly updated code, can run below commands.

git checkout [commit] [filename1] [filename2] 

git branch

When wanna change a branch name, can run the below command. It is useful when there is some issue with current branch name such as typo or update the name to reflect what is actually being done in the branch.

git branch -m [current_branch] [new_branch]

git config

This command would be helpful when trying to find configuration about the current repository of current account. It is extremely useful when sometimes wanna find some remote origin information.

# check remote prigin of current repository
git config --get remote.origin.url

What are other commands you think are pretty useful in your daily work? Can leave a comment below.

GIT LOG  GIT COMMAND  GIT 

Share on Facebook  Share on Twitter  Share on Weibo  Share on Reddit 

  RELATED


  0 COMMENT


No comment for this article.