[英]How to get the files modified in a Git Push?
I want to get all the files that has been modified in the last Push. 我想获取上次推送中已修改的所有文件。
The Push can have multiple commits. 推送可以有多个提交。
Currently I am able to to get the Modified files of last commit by this command: 目前,我可以通过以下命令获取上次提交的修改文件:
git diff-tree --no-commit-id --name-only -r HEAD
You were almost there. 你快到了 One can achieve this by comparing the current HEAD to the origin branch.
可以通过将当前的HEAD与origin分支进行比较来实现这一目标。
git diff-tree --no-commit-id --name-only -r HEAD..origin/master
git checkout master
git pull
touch addnewfile.txt
git add -A
git commit -am "added new empty file"
echo 'test' > addexistingfile.txt
git commit -am "added test in existing file"
git diff-tree --no-commit-id --name-only -r HEAD..origin/master
The last command shows then the output: 最后一条命令显示输出:
addnewfile.txt
addexistingfile.txt
git push
doesn't modify any files. git push
不会修改任何文件。
git push
adds or removes commits . git push
添加或删除提交 。 The commits have snapshots of files. 提交具有文件快照。 The commits do not have changes, they just have files.
提交没有更改,只有文件。
Here is a file: 这是一个文件:
$ cat name-of-file
I am the contents of file name-of-file.
What are the changes I made to this file? 我对此文件做了哪些更改 ? I've given you a snapshot , and my question to you is: what are the changes?
我给了您一个快照 ,我的问题是:进行了哪些更改? What key piece of information have I left out of my question?
我遗漏了哪些关键信息?
Think about this for a bit, then read on: Given two snapshots, how will you find changes? 仔细考虑一下,然后继续阅读:给定两个快照,您将如何找到更改? Does
git diff
help? git diff
帮助吗?
The git diff
command can show you what has changed between any two snapshots: git diff
命令可以显示两个快照之间的变化 :
git diff <hash#1> <hash#2>
Note that you must pick two commit hashes. 请注意,您必须选择两个提交哈希。 However, you can pick those commit hashes by names .
但是,您可以按name选择那些提交哈希。 In some existing Git repository, run:
在一些现有的Git存储库中,运行:
git rev-parse master
and see which commit hash comes out. 并查看出现哪个提交哈希。 Then run
git log master
. 然后运行
git log master
。 What's common between the output of git rev-parse
and the first line of git log
? git rev-parse
的输出和git log
的第一行之间有什么共同点?
There's a complete (if overwhelming) list of ways to produce Git hash IDs in the gitrevisions documentation , but the most useful ones for everyday work are branch names like master
, tag names like v2.1
, and remote-tracking names like origin/master
. gitrevisions文档中提供了完整的(如果压倒一切的)方式来生成Git哈希ID,但是对于日常工作而言,最有用的是分支名称(例如
master
,标签名称(例如v2.1
)和远程跟踪名称(例如origin/master
。 The name HEAD
means the current commit , 1 and you can abbreviate it @
if you like. 该名
HEAD
表示当前犯 ,1,您可以缩写它@
如果你喜欢。
1 The name HEAD
also means the current branch name . 1名称
HEAD
也表示当前的分支名称 。 The way Git decides whether you've used HEAD
to talk about a commit hash ID or to talk about a branch name is that some commands need a branch name, and others need a commit hash ID. Git决定使用
HEAD
谈论提交哈希ID还是谈论分支名称的方式是,某些命令需要分支名称,而其他命令则需要提交哈希ID。 The git rev-parse
command can ask either question, but the default is to find a hash ID. git rev-parse
命令可以询问任何一个问题,但是默认值是查找哈希ID。 You can use git rev-parse --symbolic-full-name HEAD
to ask about the branch name, or, if you're extra-serious, you can use git symbolic-ref HEAD
for this case. 您可以使用
git rev-parse --symbolic-full-name HEAD
询问分支名称,或者,如果您非常认真,可以在这种情况下使用git symbolic-ref HEAD
。
git diff-tree
is the plumbing version of git diff
for two commits git diff-tree
是两次提交的git diff
的管道版本 The command you identified, git diff-tree
, is a way to run git diff
from another computer program. 您标识的命令
git diff-tree
是从另一台计算机程序运行git diff
一种方法。 If you're running git diff
to view the difference yourself, on your own computer screen, you would normally use what Git calls a porcelain command, named after the more-polished, user-oriented parts of a bathroom like the sink. 如果您正在运行
git diff
来自己查看差异,则通常会使用Git所谓的瓷器命令,该命令以更抛光,面向用户的浴室部分(如水槽)命名。 If you're running git diff
to get differences to feed to another computer program, you might need to disassemble and re-assemble various equipment along the way, doing what Git calls plumbing , and here you would use git diff-tree
to compare two specific commits. 如果您正在运行
git diff
来获取差异以馈送到另一个计算机程序,则可能需要在此过程中分解并重新组装各种设备,执行Git所谓的plumbing ,在这里您将使用git diff-tree
比较两个具体的提交。
The git diff-tree
command has one peculiar extra feature: if you run it with just one commit hash ID, or a name like HEAD
that resolves to such a hash ID, Git will extract, from that commit, the list of parent commits. git diff-tree
命令具有一个特殊的额外功能:如果仅使用一个提交哈希ID或名称(如HEAD
解析为这样的哈希ID来运行它,Git将从该提交中提取父提交列表。 Git will then diff the commit's parent(s) vs that commit. 然后,Git将比较提交的父对象与该提交。 That's what you are seeing when you run
git diff-tree options HEAD
. 这就是运行
git diff-tree options HEAD
时看到的。
To select two commits to compare, simply use both hash IDs, or names for them, on the command line. 要选择两个提交进行比较,只需在命令行上使用两个哈希ID或名称即可。
git diff
can also compare other things git diff
也可以比较其他东西 The porcelain git diff
command can invoke, instead of git diff-tree
, the git diff-index
or git diff-files
plumbing commands. 瓷器
git diff
命令可以代替git diff-tree
来调用git diff-index
或git diff-files
plumbing命令。 These allow you to compare a commit's contents to the contents of the index , or a commit to the work-tree, or the index to the work-tree. 这些使您可以将提交的内容与索引的内容进行比较,或者将提交的内容与工作树的内容进行比较,或者将提交的内容与工作树的索引进行比较。
Remember that at all times, Git has three active copies of each file: 请记住,Git始终具有每个文件的三个活动副本:
HEAD
commit is available through git show HEAD: path
. git show HEAD: path
获得HEAD
提交中的冻结副本。 git show : path
. git show : path
查看此副本。 When you run git commit
, Git packages up whatever is in the index right then , and freezes those contents to make the new commit snapshot. 当你运行
git commit
,Git的封装了无论是在指数权的话 ,并冻结这些内容,以使新提交的快照。 This is why you must keep running git add
so often. 这就是为什么您必须经常运行
git add
原因。 The git add
command copies the contents of some work-tree file into the index, updating or even creating the index version. git add
命令将某些工作树文件的内容复制到索引中,以更新甚至创建索引版本。
It's the index version of the file that matters to Git. 对Git而言,这是文件的索引版本。 The committed versions are frozen into commits and cannot be changed.
提交的版本将冻结为提交,无法更改。 They last as long as the commit lasts.
只要提交持续,它们就会持续。 The work-tree version of each file is the one you can see and work with, but it's not the one that Git cares about.
每个文件的工作树版本都是您可以查看和使用的版本,但不是Git关心的版本。 The index version of each file is the one Git needs, in order to make new commits—and making new commits is the reason Git exists, so Git cares about commits and the index .
每个文件的索引版本是Git进行新提交所需要的文件-进行新提交是Git存在的原因,因此Git关心提交和索引 。
The work-tree is for you. 工作树适合您。 Git doesn't want or need it for anything;
Git不需要任何东西。 it's for you to work with, and in, and to copy out of to update the index, that Git needs for new commits.
Git进行新提交需要与您一起使用和导入,并进行复制以更新索引。
All of this is how, and why, Git makes snapshots . 所有这一切都是Git制作快照的方式以及原因。 Git does not deal in changes.
Git不处理任何更改。 It makes snapshots.
它制作快照。 You can, at any time, compare two snapshots to see what's different between them.
您可以随时比较两个快照,以查看它们之间的区别。 What you see will depend on which two snapshots you select.
您看到的内容取决于选择的两个快照。
You can also compare a snapshot (a commit) with a proposed snapshot (the index), or compare a snapshot to your work-tree, or compare your proposed snapshot (the index) to your work-tree. 您还可以将快照(提交)与建议的快照(索引)进行比较,或者将快照与工作树进行比较,或者将建议的快照(索引)与工作树进行比较。 The
git diff-tree
command only compares actual snapshots. git diff-tree
命令仅比较实际快照。 To obtain the other comparisons, you need one of the other plumbing commands, or the porcelain git diff
. 要获得其他比较,您需要使用其他水暖命令之一或瓷器
git diff
。
The git status
command also runs git diff
for you. git status
命令还会为您运行git diff
。 When you use git status
, it actually runs two such diffs. 当您使用
git status
,它实际上运行两个这样的差异。 One compares the current snapshot, HEAD
, to the index—to the proposed commit. 一个将当前快照
HEAD
与索引进行比较,并与提议的提交进行比较。 This is where changes staged for commit comes from. 这是为提交而进行的更改的来源。 The second comparison compares the index to the work-tree.
第二个比较将索引与工作树进行比较。 This is where changes not staged for commit comes from.
这是未进行提交的更改的来源。 Neither the index nor the work-tree have any actual changes;
索引和工作树都没有任何实际更改; the changes that
git status
or git diff
show are the result of comparing actual snapshots (commits), proposed snapshots (the index), or potential snapshots (the work-tree). git status
或git diff
显示的更改是比较实际快照(提交),建议快照(索引)或潜在快照(工作树)的结果。
You can use the below:- 您可以使用以下内容:
git diff --name-only $GIT_PREVIOUS_COMMIT $GIT_COMMIT
Or there is a function in jenkins changeSets which can be used. 或者有在詹金斯的功能变更可以使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.