Initializes the current folder as a git repository, just go to the folder and type the following at the prompt:
1
git init
Now the folder will be mark as a master
Current status of the foler:
current branch
untracked files: files that are not been added to Git repository. Use add to add.
Changes not staged for commit: still use add to update
changes to be committed: files listed below are ready to be committed
1
git status
See change details of a file:
1
git diff <file>
Add files to staging area:
1 2
git add <file(s)/folder(s)> git add . # the "." means all files
After adding some files, you can commit the current state of the folder into Git repository:
1 2
git commit # use -m <message> to add message
Show the brief log of all the commits with messages
1
git log --oneline
3. Checkout/Reset/Restore
Discard changes of the last commit, and checkout the file from an older commit. last commit -> any commit (staged)
1 2
git checkout <commit> <file> # commit means commit id, using first several chars is ok
The file changes will be automatically set into the staging area, all you need to do is submitting.
Reset a file from staged to untracked: staged -> untracked
1 2 3
git reset <commit [default=HEAD]> <file> git reset <commit-id-found-from-log> # use git log to find previous commit git reset HEAD^ # previous version
This command essentially has deeper meaning: You can return to past versions by config the <commit>.
HEAD: current version; HEAD^: previous version; HEAD^^: previous previous version...;HEAD-100: 100 versions before
Reset the staging area to untracked. (Just status, not actually discarding your changes on the files)
1
git reset
Discard changes of an untracked file: untracked -> last commit
1 2 3
git restore <file> # or git checkout -- <file>
Return to a future version? Still use commit id as reference in git reset. But how to know the commit id of a future version? Use reflog to see command history.