English 中文(简体)
吉唐:如何更改所有档案,以翻翻一番或zi一番?
原标题:Git: how to get all the files changed and new files in a folder or zip?
  • 时间:2010-11-08 17:26:20
  •  标签:
  • git

正如我的问题所说的那样,在改变档案和在我的存放处增加新档案之后,我通常把文件放在git上,但有时我需要所有经过修改的/经过改动的文档,以便组织自理。

任何选择?

最佳回答

假设你指的是你已承诺的,并想包罗目前拥有当地改建<>>/m>的所有档案(但not全新档案),你可以拿到经过修改的档案清单<>git ls-files-modised。 如果您想到最后一项承诺所改变的档案,你可使用<代码>git diff——即只有HEAD^。 你们从那儿到你们。 实例:

zip modified-files.zip $(git ls-files --modified)
cp --parents $(git ls-files --modified) ../modified-files # Linux
rsync -R $(git ls-files --modified) ../modified-files # macOS

请注意,目前正在使用目前工作树中的文档版本。

如果你在档案中拥有空间,你就不得不面对更多的麻烦。

(当然,根据你真心想做些什么,你可能会寻找git ak ash ,这堵塞了所有经修改的档案,给你留下了干净的工作树,或者你可以简单地想设立一个临时部门来承诺。)

问题回答

为了完成你的要求(假定你已经承诺并且希望建立最后一项承诺所改变的档案档案),你可以:

git archive --format=zip HEAD `git diff HEAD^ HEAD --name-only` > a.zip

如果您在一项承诺中删除了档案,以防线错使用---diff-filter=d:

git archive --format=zip HEAD `git diff --diff-filter=d HEAD^ HEAD --name-only` > a.zip

但是,也许你们实际上想要利用:

git diff HEAD^ HEAD > a.patch

and apply this patch where you need it using:

patch -p1 < a.patch

当然,如果你的目标名录已经含有旧版本的存放处,则只使用一个包件。

If you use TortoiseGIt, it provides this too.
Choose the folder, in explorer
Right click,Choose menu, TortoiseGit-> Show Log.

Select working directory and the last commiitted version.
Right click. Compare revisions. Select files you want to save/export.
Right Click. Export to folder. Done.

设想在盖特存放处中经修改和新建的档案

zip mychanges.zip $({ (git ls-files --others --exclude-standard) ; (git ls-files --modified)})

假设你没有删除或重新命名档案,就应当这样做。

<<>Copy>:

cp --parents $(git status -s | egrep "M|A|AM" | rev | cut -d" " -f1 | rev) destination_folder

<>Zip:

zip modified.zip $(git status -s | egrep "M|A|AM" | rev | cut -d" " -f1 | rev)
mkdir -p /c/temp/blah && cp $(git diff <your commit hash> --name-only) /c/temp/blah

Im在窗户上使用Gite Bash。

如果你有TortoiseGit,即便在承诺之前,你也可以把所有已改变的档案出口到文件夹(包括适当目录下的文件)。 采取下列步骤是公正的。

  1. Right click on folder which you want to see changes
  2. Select Commit to
  3. Once files are visible in box, select all files
  4. Right click - > Export selection to...
  5. Select folder where you want to put these files.
  6. Done.

Had the same requirement. Got the input from the first answer and created a tool (Windows Only) for myself. Which copies all the added/ modified files to a backup folder.

“Tool

Git-Uncommited-Files-Backup-Tool-

只是很快写道。 仅仅在个案中就帮助了某人。 (高度欢迎修改)。

此外,你也可以利用工作队时间表安排备份。

从不同的解决办法出发,这里我使用的是:

git archive --format=zip HEAD `git diff --name-only [from-commit-hash]` > changes.zip

它造成任何具体承诺的变化。

如:

git archive --format=zip HEAD `git diff --name-only 4a944407aec42222761cdc23c3e0b89a0c1e26a1` > changes.zip

这里的文字使这一过程更加容易,它将复制所有经过修改的档案,以使用固定的名录,并保持代码基的目录结构。

run: sh scr.sh

================================================================================================================================================================================================================================================================

#!/bin/sh
FILES=`git ls-files --modified`
for x in $FILES
do
        prev_dir=$PWD
        echo "MY Dir = $prev_dir"
        mkdir -p $1/$x
        cd $1/$x
        cd ../
        rm -r *
        cp $prev_dir/$x ./.
        cd $prev_dir
done

================================================================================================================================================================================================================================================================

You can export your last modified files via git ls-files --modified Just create a .sh file with the following code And execute it.

#!/bin/sh
FILES=`git ls-files --modified`
export_dir="place your export dir"
for x in $FILES
do
   prev_dir=$PWD
   folder=$(dirname $x)
   echo "Exporting to..." $export_dir/$x
   cp $prev_dir/$x $export_dir/$x
done

请注意,其他答复中所列的<条码>git ls-files-modised指挥系统不包括新的档案。

I ve一直在使用以下指挥系统,以备new,如果我的民主选举学会从边远处进行编织,其“Smart 校外”特征是 t:

cp --parents $(git status -s | egrep "^A|^ M" | cut -c 4-) ../modified-files # Linux
rsync -R $(git status -s | egrep "^A|^ M" | cut -c 4-) ../modified-files # macOS

让我们研究我们如何获得新的和经过修改的档案清单:

git status -s | grep "^A|^ M" | cut -c 4-
  • -s stands for --short and it will produce an output like this:

     M .gitignore
    A  _includes/code/howto/manage-data.create.py
    A  _includes/code/howto/manage-data.create.ts
     M _includes/code/howto/search.generative.ts
     M _includes/code/howto/search.hybrid.ts
    AM developers/weaviate/manage-data/create.mdx
    ?? _includes/code/howto/jeopardy_1k.csv
    
  • ded orM

  • cut -c 4- cuts those first 3 characters and returns the filename starting from the 4th character

其他选择是:





相关问题
git confusion - cloning a repo is returning a past version

Im having some confusion with my git usage. I cloned a repo from one comp to the other, and the new clone is the state of the original that was active some time ago. So its cloning a past version. ...

Appropriate strategy for tagging and hotfixing with git

I was wondering if the strategy I m using for tagging and hotfixing tags (which then I use for deploying rails applications) with git is appropriate. For tagging I just tag a commit of the master ...

Tips on upgrading CVS to git/hg?

We still use CVS, I use git and hg for my personal use though I m still a novice at both, but I realize they re much more modern and better, faster, distributed, etc. It s just everyone is so ...

Using Git in a TFS shop

Using Git at home has spoiled me - I now find using TFS at work to be a bit of a drag and want to explore the possibility of using Git locally and syncing somehow with TFS. I figure there are a few ...

热门标签