0

In a Kotlin repo, I have made changes to a number of files and also moved them (manually, not using git.)

As a first step, I do not want to commit all changes, instead just commit the changed package names at the top of each file.

Currently nothing is staged and I see a number of deleted files and a number of untracked files.

git add -p doesn't seem to help me here. How can I commit parts of the moved files -- if possible without naming them individually?

Felix Dombek
  • 13,664
  • 17
  • 79
  • 131
  • https://stackoverflow.com/questions/6436681/how-to-stage-only-part-of-a-new-file-with-git – dippas Jul 13 '22 at 11:51
  • If `git add -N` followed by `git add -p` works in your Git version (it does in many), that's probably the way to go here. – torek Jul 14 '22 at 01:29
  • @torek Actually it doesn't. (2.35.1) – Felix Dombek Jul 14 '22 at 08:54
  • OK - in that case, consider `git add`, followed by `git reset -p`. Or (I know this is crude, but it's what *I* usually do, because it's really simple and obvious): make a temporary copy of the file `foo.ext.full`, then edit the file down to the part you want to add, then `git add foo.ext`, then `mv foo.ext.full foo` to put the full one back. – torek Jul 14 '22 at 09:32
  • (I did try `git add -N` followed by `git add -p` here, with an older Git—2.27—and it worked. I just tried it again with Git 2.37.0.3 and it works here too. You do have to select "edit" and then trim away all but the `+` lines you want.) – torek Jul 14 '22 at 09:36

0 Answers0