In the daily development process, a piece of code content is added and deleted are sparse and common things. This also causes us to encounter two problems in our daily development work.
- Who added the content of this code, has it always existed or has been modified many times?
- A piece of code was deleted, who deleted it?
Here we illustrate with a concrete example.
There is a hosts.txt file with the content
Now we have a situation like this
- The earliest host.txt contains the introduction of lib/c
- But in a certain version lib/c was removed by someone
- We want to determine who and which commit removed this lib/c
We can use this script to achieve this, the script is very simple as follows.
1 2 3 4 5 6 7
Call the script to view
1 2 3 4 5 6 7 8 9 10 11 12 13
Yes, through the above script, you can easily check the history of adding and deleting a piece of content. Is it very convenient and fast and effective.
Say goodbye to Git blame
Existing content tracking history
- git blame can only view the most recent modification,
- The method in this paper can check the modification history of a content. For example, information such as adding-deleting-adding a piece of content can be found.
Remove content tracking
- git blame cannot view information about non-existing code snippets
- This method can view the historical information of the deleted content
Git is a good thing, make good use of it, especially the terminal git command, you will easily be efficient, fast and accurate in dealing with problems.
This article is reprinted from https://droidyue.com/blog/2022/06/13/a-little-git-log-case-can-do-big-help/
This site is for inclusion only, and the copyright belongs to the original author.