Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git reset files with typechange status

Tags:

git

symlink

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?

like image 769
iphipps Avatar asked Jul 02 '14 14:07

iphipps


People also ask

Does git reset hard remove unstaged files?

git reset --hard resets your index and reverts the tracked files back to state as they are in HEAD. It leaves untracked files alone. @fifigyuri -- correct.

When running git reset the affected files will change state?

Comparatively, git reset , moves both the HEAD and branch refs to the specified commit. In addition to updating the commit ref pointers, git reset will modify the state of the three trees. The ref pointer modification always happens and is an update to the third tree, the Commit tree.

Does git reset change files?

It resets the index, but not the work tree. This means all your files are intact, but any differences between the original commit and the one you reset to will show up as local modifications (or untracked files) with git status.


2 Answers

git status | grep typechange | awk '{print $2}' | xargs git checkout 
like image 99
muzz Avatar answered Oct 17 '22 23:10

muzz


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.

like image 22
zzxyz Avatar answered Oct 18 '22 00:10

zzxyz