0

In my situation, I have a webapp (django) project that has a bunch of staged files I'd not like to discard or commit, but at the same time, I have a file (a sqlite file) that I want to add and commit. At this moment since I have no idea how to do this, I'm taking a way to manually copy (cp) the file to an another non-git directory with renaming, but this is apparently not an efficient practice. So what can I do? Thanks.

2 Answers2

0

stash the staged files, then add and commit the file you want and pop the stash back.

eis
  • 51,991
  • 13
  • 150
  • 199
0

Specify the file that you want to commit:

git commit -m 'commit the file' -- /path/to/file

This will commit the specified file but other staged files will not be committed.

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
  • That would be what I wanted, but as I'm trying the command I get `did not match any file(s) known to git.`. – 丶 Limeー来夢 丶 Mar 05 '22 at 10:25
  • e.g. `$ git commit -m "sqlite tmp" db.sqlite3` `error: pathspec 'db.sqlite3' did not match any file(s) known to git.` The file is certainly there and accessible. The file is also not in the gitignore or on the matches. – 丶 Limeー来夢 丶 Mar 05 '22 at 10:25
  • Try adding two hyphens before the path (but leave a space between the hyphens and the path). – snakecharmerb Mar 05 '22 at 10:29
  • Thanks for the edit, but it still doesn't work (`git commit -m "sqlite tmp" -- db.sqlite3`); I get the same above error – 丶 Limeー来夢 丶 Mar 05 '22 at 10:49
  • Ah, I misread the error: `did not match any file(s) known to git` means that the file is not tracked by git; you need to do `git add db.sqlite3` before committing. – snakecharmerb Mar 05 '22 at 10:54
  • made it, thanks. But I googled "git commit specific files" and found a SO post https://stackoverflow.com/questions/7239333, no one mention to the trick `--`. I'd like to learn is there any SO post or document that elaborate this? – 丶 Limeー来夢 丶 Mar 05 '22 at 11:14
  • 1
    https://stackoverflow.com/questions/13321458/meaning-of-git-checkout-double-dashes – snakecharmerb Mar 05 '22 at 11:16