Git:如何获取所有文件更改以及文件夹或zip中的新文件? [英] Git: how to get all the files changed and new files in a folder or zip?

查看:162
本文介绍了Git:如何获取所有文件更改以及文件夹或zip中的新文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如我的问题所述,在更改文件并在存储库中添加新文件后,我通常会使用 git 提交文件,但有时需要将所有已修改/更改的文件复制到文件夹中才能组织 - 我自己的理由。



任何选项? 假设你的意思是你还没有提交,并且想要打包当前有本地修改的所有文件,可以使用 git ls-files --modified 来获取修改文件的列表。 。如果您想要上次提交时更改的文件,您可以使用 git diff --name-only HEAD ^ 。你从哪里去,取决于你。例子:

  zip modified-files.zip $(git ls-files --modified)
cp $(git ls-files --modified)../modified-files

请注意,这是使用文件在当前工作树中。



如果文件名中有空格,则必须更加麻烦。



(当然,根据你真正想做的事情,你可能正在寻找 git stash ,它存储了所有修改过的文件,并为您留下一个干净的工作树,或者您只需要创建一个临时分支来提交到。)


As my question says, after changing files and adding new files in my repository, I normally commit files with git, but sometimes I need all the modified / changed files copied to a folder for organizing-myself reasons.

Any option?

解决方案

Assuming you mean you haven't yet committed, and want to package up all of the files that currently have local modifications, you can get the list of modified files with git ls-files --modified. If you want the files which were changed by the last commit, you could use git diff --name-only HEAD^. Where you go from there is up to you. Examples:

zip modified-files.zip $(git ls-files --modified)
cp $(git ls-files --modified) ../modified-files

Note that this is using the versions of files in the working tree currently.

If you have spaces in filenames, you'll have to go to a little more trouble.

(Of course, depending on what you're really trying to do, you might be looking for git stash, which stashes away all modified files and leaves you with a clean working tree, or you could simply want to make a temporary branch to commit to.)

这篇关于Git:如何获取所有文件更改以及文件夹或zip中的新文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆