Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the practical tips for git

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what are the practical tips of git". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the practical tips of git"?

Who touched my code?

Who touched my code?

Whose bug points to my head?

This problem often occurs when working as a team. At this point, you can use git blame to locate the last change to the code. However, there is a problem, which does not see the previous changes in this line of code. For example, when someone on the project team formats all the code, git blame is useless. At this point, you can use it in conjunction with another useful command, git log-p, to view the change history and details of the file, and finally find out who should carry the pot.

Git blame-L 10, 12 package.json

Git log-p-L 10 ~ (th) ~ (th) 12 ~ (th) package.json quickly switch merging branches.

When you often work on branches An and B, you need to cut back. The command should be git checkout A, but here is a simpler command, git checkout -, to cut to the nearest branch. If you need to merge the contents of Branch B, you can use git merge -.

Beside the point, cd-represents access to the most recent directory, which is also quite practical.

Git checkout-

Git merge-Statistics item

Count the commit of each member of the project. For example, you can check the number of commit of your own project and the contribution of others to your project.

Git shortlog-sn

Git shortlog-sn-- no-merges # does not include merge commit Quick location submission

If your commit message is standard, such as associating the number of issuse or current task or bug, quickly locate it according to commit message: git log-- grep "Add".

If your commit message is not very standard, only remember which lines of code have been changed, you can also look up the keyword according to the information submitted each time, which is git log-S "setTimeout".

At the same time, it can also assist rapid positioning according to the author and time.

Git log-since= "0 am" # to view today's submission

Git log-author= "shfshanyue" # View the submission of shfshanyue

Git log-grep= "# 12" # find the submission of the replacement keyword in the submission information

Git log-S "setTimeout" # View the submission quick positioning string of the package switch machine in the submission

How do I find all the files with replacement keywords?

You can search globally using VS Code, or you can search globally through grep-rn using grep.

However, they also search for ignored files, such as the two famous folders node_modules and public (dist/build) on the front end. Although grep can specify-- exclude to ignore files, git is more convenient.

At this point, you can use git grep to solve this problem, and ag can also solve this problem.

Grep-rn

Grep-rn-exclude config.js-exclude-dir node_modules

Git grep

Ag thank you for your reading, these are the contents of "what are the practical tips for git?" after the study of this article, I believe you have a deeper understanding of what practical tips for git have, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report