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

How to realize Fast Positioning and submission with git

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

Share

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

This article introduces the knowledge of "how to use git to quickly locate and submit". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

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 submissions with keywords in the submission information

Git log-S "setTimeout" # View the submission Quick location string containing keywords 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

This is the end of ag's "how to use git to quickly locate and submit". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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