![]() ![]() While you can restrict it to a subset of files, I usually use it when there are a lot of different changes strewn across the whole repository. Interactive mode is designed to make it easier to review and manipulate changes in the whole repository. So powerful that it has its own little submenu:ġ: tatus 2: pdate 3: evert 4: dd untracked interactive enters the interactive mode, and is a bit more powerful. patch only lets you decide about the individual hunks in files. interactive (or -i) is the big brother of -patch. Git will then abort the editing process and leave the hunk unchanged, returning you to the standard selection. If you edit your hunks often enough you’ll eventually get the hang of it.Īnd if you decide that you don’t want to edit the hunk after all, simply delete everything in the file, save & close it. Exactly how you create a sensible diff seems to be a bit of an dark art (at least to me right now), but you should always keep in mind how the original file looked like, and then plan your -s and +s accordingly. “Sense” means that it can be applied cleanly. The other thing is that the diff still has to make sense. This means you’re adding an additional space to the whole line, which in turn means the diff algorithm can’t find/match the line in the original file, which in turn means Git will yell at you. I’d mark a line with a - to be removed, but in most text editors that inserts a -, it doesn’t overwrite the space that was there before. One thing that tripped me up quite often was that I forgot the one character indent. Edit again?” so often, you’ll start to hate yourself for your inability to figure this out, even though it seems so easy (or Git because it can’t figure out what you want). If you’ve never done this before, Git will tell you “Your edited hunk does not apply. Since you’ve got the diff open in your favorite text editor (you did configure Git to use your favorite text editor, right?), you can do whatever you want - as long as you make sure the resulting diff applies cleanly.Īnd therein lies the trick. Anything else, and you’ll get errors (there’s no character for a changed line, since those are handled by removing the old line, and adding the changed one as new). The character can either be a space (indicates an unchanged line), a - indicating that the line was removed, or a + indicating that the line was added. The most important thing to keep in mind: The diff is always indented with one character in addition to whatever other indentation is there. Manually editing the hunk is immensely powerful, but also a bit complicated if you’ve never done it before. As promised, it will open the hunk in a text editor and you can edit it to your hearts content This is probably the most powerful option. This only works if there’s unchanged lines between the changes in the displayed hunk, so this wouldn’t have any effect in the example above s - Split the hunk into smaller hunks.Useful if you’ve already added what you want to, and want to skip over the rest d - No, don’t add this hunk and all other remaining hunks.Pressing ? will give you a short explanation for each one, but the ones I use most often are: + $stderr.puts "Couldn't attach function #"Īt the top is some diff info about the current position in the file, followed by the actual diff of the source code (called “hunk”), and below that are your available options. ![]() When you pass this option to add, instead of immediately adding all the changes in the file to the index, it goes through each change and asks you what you want to do, and looks like this: -24,7 +32,12 module CoreMIDI I use this option so often that I’ve added a git alias for easy access: git config alias.ap "add -patch". Normally, calling git add will add all the changes in that file to the index, but add supports an interesting option: -patch, or -p for short. With Git, on the other hand, you first add all the changes you want to be in the next commit to the index via git add (or remove a file with git rm). Note: Depending on your version of git, your output might differ slightly. In other systems whenever you make a commit, all the changes you made in your working copy are committed. The index is the place where you prepare your next commit. One of the things that is pretty much unique to Git is the index (also known as the cache or staging area).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |