Git reset files with typechange status
Asked Answered
L

3

31

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?

Logogram answered 2/7, 2014 at 14:11 Comment(1)
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.Longspur
C
57
git status | grep typechange | awk '{print $2}' | xargs git checkout
Carse answered 13/12, 2014 at 16:28 Comment(2)
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 checkoutCentrist
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 checkoutTithe
D
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.

Decelerate answered 2/11, 2018 at 23:25 Comment(0)
S
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

Stoical answered 2/7, 2014 at 14:31 Comment(1)
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.Logogram

© 2022 - 2024 — McMap. All rights reserved.