sách gpt4 ăn đã đi

git - 查看特定行的git历史

In lại 作者:太空狗 更新时间:2023-10-29 13:29:50 29 4
mua khóa gpt4 giày nike

我想查看与文件中特定行相关的提交历史。我知道我们可以获得文件的历史记录。是否有任何命令可用于仅对与某一特定行相关的提交进行排序?

câu trả lời hay nhất

bomz 给出了正确的选项,但语法错误。固定线路看起来像这样:

git log -L '/the line from your file/,+1:path/to/your/file.txt'

-L 参数的含义是“在 path/to/your/中找到正则表达式 /the line from your file/ 的第一次出现file.txt 并显示关于从这一点开始的一行范围的日志(意思是,只有这一行,但你可以说 +5 代替)。

需要注意的是,如果该行包含在正则表达式中具有特殊含义的字符,您需要对它们进行转义。

Nhưng,使用行号可能会简单得多,如下所示:

git log -L15,+1:'path/to/your/file.txt'

(对于文件 path/to/your/file.txt 的第 15 行)

在这两种情况下,+1 都可以替换为更大的数字以获得更多行,或者替换为正则表达式以匹配所选范围的末尾。

từ the docs 的详细说明:

-L ,:
-L ::

Trace the evolution of the line range given by "," (or the function name regex ) within the . You may not give any pathspec limiters. This is currently limited to a walk starting from a single revision, i.e., you may only give zero or one positive revision arguments. You can specify this option more than once.

and can take one of these forms:

  • con số

    If or is a number, it specifies an absolute line number (lines count from 1).

  • /regex/

    This form will use the first line matching the given POSIX regex. If is a regex, it will search from the end of the previous -L range, if any, otherwise from the start of file. If is “^/regex/”, it will search from the start of file. If is a regex, it will search starting at the line given by .

  • +offset or -offset

    This is only valid for and will specify a number of lines before or after the line given by .

If “:” is given in place of and , it is a regular expression that denotes the range from the first funcname line that matches , up to the next funcname line. “:” searches from the end of the previous -L range, if any, otherwise from the start of file. “^:” searches from the start of file.

关于git - 查看特定行的git历史,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50469927/

29 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress