gpt4 book ai didi

git 命令来比较 git status 输出的第 n 个修改文件

转载 作者:太空狗 更新时间:2023-10-29 14:17:04 24 4
gpt4 key购买 nike

我经常运行 git status然后想查看其中一个文件的具体差异。所以之后:

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: path/to/modified/file1
modified: path/to/modified/file1

是否有可能使用 git 或作为后备 bash 到 git diff第 n 个修改的文件,因此 git diff <someMagic(2)>会减少到git diff path/to/modified/file2 .

我的主要问题是这是否存在于 git 中,如果不是为了帮助 bash 命令。

最佳答案

如果自动化不是您的目标,那么我会说 git add -i适合您的情况。

看看git add -i文档。

如果您正在寻找一个脚本,那么我已经做了一些完全符合您要求的事情:

#!/bin/bash
git diff $(git status | grep modified | sed 's/^.*: //' | head -n "$1" | tail -n 1)

使用方法是调用它,然后传入要diff的修改文件的编号:<script_name> N ,其中 N 是“第 n 个修改的文件”的编号。

(例如,使用您的示例,如果我调用 <script>.sh 2,它会像这样调用 diff:git diff path/to/modified/file2)

关于git 命令来比较 git status 输出的第 n 个修改文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46305978/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com