After checking git status look through my modified files. But how to choose them individually? - I will explain. I want to split 9 files into 3 commits each with n number of files.
4 answers
$ git status Untracked files: 1.json 2.json $ git add 1.json $ git commit -m 'add 1.json file' $ git status Untracked files: 2.json $ git add 2.json $ git commit -m 'add 2.json file' $ git status On branch master nothing to commit, working directory clean multiple files are added like this:
$ git add 1.json 2.json $ git commit -m 'add 1.json , 2.json' can be masked:
git add .- add all files,git add m*- add all files starting withm.
add files to the index (also called stage , stage area or cache ) and then commit.
now three files are modified:
$ git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: file1 # modified: file2 # modified: file3 # no changes added to commit (use "git add" and/or "git commit -a") add file1 and file2 to the index:
$ git add file1 file2 $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: file1 # modified: file2 # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: file3 # make commit:
$ git commit -m 'добавили изменения в file1 и file2' ... $ git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: file3 # no changes added to commit (use "git add" and/or "git commit -a") and now we can continue the same thing ( add + commit ) for file3 .
Git allows very flexible commit. You can even commit the "file floor".
First, we write git add -i and go online to add files to the commit.
It will be displayed something
$ git add -i staged unstaged path 1: unchanged +0/-1 TODO 2: unchanged +1/-1 index.html 3: unchanged +5/-1 lib/simplegit.rb *** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: help What now> select 5 (or p) and hit enter. Next, the git will show a list of files and hammering in their numbers, you can select the files that will "add." press enter at the end.
After that, enter a special mode and you will be shown one small change (they are called hunks or chunks). With each change, you can either immediately add (y) or refuse (n) or ask the git to break into smaller pieces (s)
after successfully passing through all the pieces, just exit (q).
Now you need to see what will be commited. git status and git diff --staged will help here (it will just show what exactly gets into the commit).
If everything is ok, then you can run git commit -m "text" and commit.
This process is then repeated until the quantity and quality of commits is received.
Read more about this in Russian
This method is very convenient, since it allows you not to commit any temporary code that you don’t want to delete (for example, for debugging purposes).
To commit multiple files, list their names: git commit file1.txt file2.txt file3.txt
git statusreport? - Nick Volynkin ♦ 2:49 PM