30

When finding and replacing across a large repository, I get a bunch of files with a typechange status. These are mostly symlinks.

Rather than

git checkout -- eachfile.name

Is there a way to reset only typechange files?

iphipps
  • 529
  • 1
  • 7
  • 20
  • 2
    Not sure if it matters, but `git config core.symlinks true` helped me with Sourcetree automatically marking checked out files as modified. Setting symlinks to true, resolved the issue. – Danijel Jun 04 '20 at 10:53

3 Answers3

57
git status | grep typechange | awk '{print $2}' | xargs git checkout
JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
muzz
  • 4,324
  • 2
  • 24
  • 14
  • 1
    I had to change it to ```awk '{print $3}'``` otherwise it wasn't getting the filename. ```git status | grep typechange | awk '{print $3}'|xargs git checkout``` – Mick T Mar 06 '19 at 20:07
  • Works only if the filenames don't contain spaces. To overcome this one can do `git status | grep typechange | cut -d' ' -f2- | xargs -d'\n' git checkout` – Jean Paul Jun 03 '20 at 23:11
7

Flavor of the existing answer, but I prefer it:

git status --porcelain | awk '{if ($1=="T") print $2}' | xargs git checkout

--porcelain is designed for this kind of use.

Note that this awk answer and the existing answer can be broken with filenames containing spaces, linefeeds, etc in which case we can use.

git status -z | perl -0 -ne 'print $1 if /^\s*T\s*(.+)$/s' | xargs -0 git checkout

git status -z is the one really recommended for this kind of use and null terminates each entry. perl's -0 deals with that ,-ne processes the given command for each line (or "entry" really). $1 refers to the first capture group here, which will include the file name and null terminator.

zzxyz
  • 2,953
  • 1
  • 16
  • 31
2

In most times its better to remove symlinks from your repository. If you work under different operating systems its a problem to have the links in your repository.

When you remove it and set it to a new location your file is modified.

Some Java Git client have problems with symlinks. They try to follow them and you get an error. I had this problem with the Jenkins client.

To add all symlinks to the .gitignore you can run the following command under Linux

find /your/directory -type l >> .gitignore

René Höhle
  • 26,716
  • 22
  • 73
  • 82
  • Not adding symlinks to git is definitely good practice. Unfortunately, in this repository the workflow is to branch off, commit, then merge request. The master branch is production; and I don't have access to commit directly to it or change untracked files in it. The use case is for versioning libraries. That is to symlink a 'current' folder to the current version of jQuery as an example. For when jquery updates, I drop the new version and symlink the 'current' dir to it. The allows me to update a library without changing html refs through a ton of files. – iphipps Jul 02 '14 at 19:41