- Create a repository
- Register files/directories to Index
- Commit indexed files
- See a list of changed files
- View differences in changed files
- View commit log
- View a commit detail
- Move/change the name of a file/directory
- Delete a file
- Remove untracked files from working tree
- Restore a changed file in the working tree
- Remove a file from the index
- Register changes from only files that have been added to the index
I want to create a repository.
$ git init
Run the command "init" in the directory in which you want to create a repository.
Register files/directories to Index
$ git add <filepattern>
In the file pattern, you can specify individual or multiple files and directory names to be added to the index. You can either specify the file name directly or use wild card symbols such as *.txt . Putting . in the filepattern will register all changed files on the index including files within sub-directories.
If you add a -p option, you will be prompted to accept/reject specific sections of a changed file. If you add a -i option, you can register changed files interactively.
Commit indexed files
$ git commit
The -a option is like a shortcut that detects changed files (except for newly added files), adds them to the index, and commits them.
The -m option allows you to commit and specify a commit message at the same time. If you do not specify -m, a text editor will open prompting you to enter a commit message.
See a list of changed files
$ git status
Adding the -s option will only display the names of files that have been changed.
Adding the -s option followed by -b option will include the branch name in the output.
View differences in changed files
$ git diff
The "diff" command will by default show the differences between the working tree and the index.
If you add the --cached option, the differences between the index and HEAD will be shown.
If you assign HEAD or a commit ID, the differences between the working tree and the assigned HEAD/commit will be shown.
View commit log
$ git log
"log" will by default show a list of commits of the branch.
Specifying a file name will show a log of commits only for that given file.
View a commit detail
$ git show <commit>
Specify the commit ID that can be found through the log command or HEAD to the parameter of the show command.
Move/change the name of a file/directory
$ git mv <oldfilename> <newfilename>
Delete a file
$ git rm <file>
Remove untracked files from working tree
$ git clean
Adding the -n option will only show the files that will be removed. Adding the -f option will actually remove the files.
By default, files listed under the .gitignore configuration file will not be removed. If you specify the -x option however, the files listed under .gitignore will be removed from the working tree.
Restore a changed file in the working tree
$ git checkout -- <file>
Remove a file from the index
$ git reset HEAD -- <file>
Register changes from only files that have been added to the index
$ git add -u