如何从补丁获取行的git日志?

时间:2020-07-06 04:54:59

标签: git git-log git-patch

我使用命令获得补丁:

git format-patch -1 --numbered-files --unified=100000 -o tmpdir commit_sha1 --file_name

现在,我对补丁中特定文件中的特定行感兴趣。我想查看此行的更改历史记录。 我可以这样使用git日志:

git log -L10,10:file_name

但是问题是补丁中的行号与原始文件中的行号不匹配。

有没有办法从补丁中获取行的git log?

1 个答案:

答案 0 :(得分:0)

我不确定我是否了解您的需求。

如果您想在知道行的内容后看到提交的内容,可以使用use std::{ fs::File, io::{self, BufRead, BufReader}, fs::OpenOptions, fs::write, any::type_name, path::Path, io::Write, }; fn type_of<T>(_: T) -> &'static str { type_name::<T>() } fn main(){ let inpath = Path::new("tool_output.txt"); let outpath = Path::new("test_output.txt"); let indisplay = inpath.display(); let outdisplay = outpath.display(); let mut infile = match File::open(&inpath) { Err(why) => panic!("couldn't open {}: {}", indisplay, why), Ok(infile) => infile, }; let mut outfile = match OpenOptions::new().write(true).append(true).open(&outpath) { Err(why) => panic!("couldn't open {}: {}", outdisplay, why), Ok(outfile) => outfile, }; let reader = BufReader::new(infile); for line in reader.lines() { let format_line = String::from(line.unwrap()); // <- I thought this would fix the error but it didnt. println!("Type = {}", type_of(&format_line)); let _ = writeln!(outfile, &format_line).expect("Unable to write to file"); <- this is currently causing the error. //write("test_output.txt", line.unwrap()).expect("Unable to write to file"); } }

error: format argument must be a string literal
  --> text_edit.rs:36:28
   |
36 |     let _ = writeln!(outfile, format_line).expect("Unable to write to file"); 
   |                               ^^^^^^^^^^^
   |
相关问题