0

I have a large code repo I work with that, once compiled, litters the git source tree with about 3000 extra files (.os, .sos, etc), as well as a few hundred other file changes (autogenerated files, permissions, etc). So I've gotten used to doing a git clean -f and git reset --hard HEAD before every pull, to avoid the mountains of conflicts I would get.

I'm trying to automate this into a pretty little script, but I can't find any way to redirect the output of git clean. Specifically, I'm doing something like this:

(in fish-shell)

set -l linecount ( git clean -n | wc -l )
git clean -f | pv -l -s $linecount

I've tried setting pv to be the $PAGER and enabling --paginate, no luck. I've tried various combinations of the pipe like 2>&1 | to no avail.

Anyone know how to make this work?

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
Yeraze
  • 3,269
  • 4
  • 28
  • 42
  • And please no answers about "I'm doing this the wrong way"... .gitignore's and such won't work here, this is a 3rd party repo that I'm importing and working with, and they do this all in SVN. – Yeraze Jan 02 '14 at 15:33

2 Answers2

1

Typically this would be done by explicitly ignoring your .o, .so, etc. files in your .gitignore file.

A sample file might look like this:

# Ignore compiled objects
*.o
*.so

The .gitignore file should be committed to your repository so other developers can benefit from it. For files that you want to ignore only on one copy of the repository, you can use .git/info/exclude, which will not be included when you push.

A good starting point for creating this file is gitignore.io, which lets you submit languages, systems and tools that you are using and spits out a useful ignore file.

If these files have already been committed, ignoring them will not work. In that case you have a few options:

  1. Remove the committed files from the repository with git rm --cached. Note that this will affect other users; the next time the fetch those files will be deleted from their machines. You may have to coordinate carefully.

  2. Tell Git to assume the files to be unmodified with git update-index --assume-unchanged.

Community
  • 1
  • 1
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • Unfortunately that won't work in this case. This is a 3rd party vendor repo, that I'm importing from their SVN. They commit their binaries as well as the source, so every time we rebuild there are dozens of changes. In addition, their build process is just a bunch of batch files that don't properly look for timestamps or existing files, so I have to manually purge between compiles. – Yeraze Jan 02 '14 at 15:28
0

Doh.. Seems this was user error...

pv echoes input to output. Duh.. Correct syntax should have been:

git clean -f | pv -l -s $linecount > /dev/null

And now it works!

Yeraze
  • 3,269
  • 4
  • 28
  • 42