Pergunta

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?

Foi útil?

Solução 2

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!

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top