Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git checkout --patch by words?

Tags:

git

vim

patch

We have a project where the files contain unfortunately long lines, with no possibility of shortening them. We could streamline our workflow significantly if we could use git checkout --patch also with such files. This does not work since if there is any change in the whole huge line, the line gets flagged as changed.

Usually, we inspect such changes using git diff --word-diff. Is there a possibility to make checkout --patch work with similar format? Are there any other means to work around our problem?

like image 821
aleator Avatar asked Jan 10 '13 08:01

aleator


People also ask

How do I checkout a specific commit?

To checkout a previous commit, you will use the Git checkout command followed by the commit hash you retrieved from your Git log.

What is the command git checkout Branchname do?

Assuming the repo you're working in contains pre-existing branches, you can switch between these branches using git checkout . To find out what branches are available and what the current branch name is, execute git branch .

How do I checkout a tag?

In order to checkout a Git tag, use the “git checkout” command and specify the tagname as well as the branch to be checked out. Note that you will have to make sure that you have the latest tag list from your remote repository.

How do I force checkout in git?

Force a Checkout You can pass the -f or --force option with the git checkout command to force Git to switch branches, even if you have un-staged changes (in other words, the index of the working tree differs from HEAD ). Basically, it can be used to throw away local changes.


1 Answers

After some trying around, I got this answer to work and figured out how to use it for your checkout. I made some additional changes to squelch a warning that would sometimes be printed and had to fix the argument parsing to be a bit more flexible. (Since this is originally a plumbing script where the arguments get pre-processed by the git core, this is not necessary in the original version).

You can use this version of the file (raw file for save-link-as convenience) and copy it to somewhere in your PATH, as described in the linked answer. Be sure to also set its executable bit (chmod +x path/to/file) after downloading.

Assuming you named the file git-add--interactive--words as suggested, you can use the following command to define an alias for it:

git config --global alias.cop add--interactive--words --patch=checkout

Now you can do something like:

git cop HEAD~5 to do an interactive checkout of . (current dir) 5 commits ago, or
git cop master -- docs/README to interactively check out docs/README from branch master

You can call the alias anything you want, of course (I chose cop here for 'c'heck'o'ut --'p'atch).

I know this answer is really late so it's possibly not applicable for you anymore, but this question has been on the unanswered list for so long that I just had to figure it out today -- maybe it'll help someone else ;)

like image 108
Nevik Rehnel Avatar answered Sep 27 '22 22:09

Nevik Rehnel