0

I have a work folder with many GIT and SVN repositories. Since the committed revisions are all available in the server, I just need to backup the unversioned files (modified but not committed, not versioned, and ignore the internal git/svn metadata).

I assume that for Windows the best approach is using Powershell pipeline to list all files, filter out according to their status (ignore the unmodified ones), and pipe those files into 7-zip stdin (or intermediary list of files) for back up.

Which command should I use?

1
  • 1
    Probably the best approach is to branch, commit, and push to a new remote (which can be a simple git repo/folder on your backup drive/server). Work with your version control, not around it.
    – Bob
    Commented Aug 8, 2018 at 1:27

1 Answer 1

1

I doubt there's a single command to run. You're going to need a combination of tools running in sequence here.

Git includes an argument to list all files inside the repo: git ls-files

If you want to list only the untracked and modified files, you can use the -o and -m arguments:

git ls-files -o -m

If you pipeline that into a PowerShell function, it'll come in as an array, and you can iterate over all those files and do whatever you want with them. (I don't know SVN well, but presumably there should be a similar command there.)

Here is a script file which looks for a .git file in your current working directory, calls git ls-files -o -m, and pipes that output to another function that goes through each file and prints its full path. You could copy or move or whatever you wanted with each file:

function DoSomethingForGitLsFiles {
  param(
    [array]$FileList
  )
  Write-Host $FileList.count 'files found:'
  foreach ($FilePath in $FileList)
  {
    # This is where you could copy your files out somewhere else.
    Write-Host "FILE: $(Get-Location)\$FilePath"
  }
}

function FindGitRepo {
  param(
    [string]$searchPath
  )

  if (Get-ChildItem -Name -Path "$searchPath\*.git") {
    DoSomethingForGitLsFiles (git ls-files -o -m)
  } else {
    Write-Host "No .git repo found."
  }
}

FindGitRepo -SearchPath (Get-Location)

Once your files are in a separate location, you could easily run 7-zip on the folder, etc...


That said, it sounds like what you might want instead is either a branch with just the needed changes which you could cherry-pick atop any other changeset, or perhaps a stash that you could reapply atop a changeset and then revert at-will.

https://git-scm.com/docs/git-stash

(Depending on your use case, stash may not quite be enough, but it's less well-known, so maybe it'll be useful.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .