How git works
-
files can be
untracked
- that is not beign tracked by gitunmodified
- that is they are tracked by git, but are not modified since last commitmodified
- that is they are modified since last commitstaged
- that is files which are ready to be commited
-
git init
- create a git repo git clone https://github.com/shivanshu-semwal/ds-ml
- clone a repo overhttps
git clone git@github.com:shivanshu-semwal/ds-ml.git
- clone a repo overssh
git add [filename]
- start trackingfilename
git status
- show status of files, (untracked
,unmodified
,modified
,staged
)git status -s
- show git status in short- it will show 3 columns
- first one show file status in staging area
- second one show file status in the working tree
- this one shows the file name
??
- means file is untrackedA
- means file is added to tracking areaM
- means file is modified
git commit -m "Title" -m "Description"
- commit the file in the staging area, the becomeunmodified
after commitinggit commit -a -m "msg"
- skip staging area and directly commit all changes to tracked files, removes the need to dogit add
git rm [filename]
- make a file untrackedgit rm --cached [filename]
- remove a file form staging area, accidently stagedgit mv [filename] [newfilename]
- change name and location of a tracked filegit diff
- show the changes in current working treegit diff --cached
orgit diff --staged
- show the change in the files in staged area, useful to check what will be on next commitgit log
- show commit history, in reverse chronogical ordergit log -p
- show commit history, and also the files change and what changedgit log -2
- show last two commitsgit log --stat
- show git log in summarygit log --pretty=oneline
- show git logs in one linesshort
full
fuller
- also you can give custom format,
git log --pretty=format:"format"
Specifier | Description |
---|---|
%H | Commit hash |
%h | Abbreviated commit hash |
%T | Tree hash |
%t | Abbreviated tree hash |
%P | Parent hashes |
%p | Abbreviated parent hashes |
%an | Author name |
%ae | Author email |
%ad | Author date (format respects the --date=option) |
%ar | Author date, relative |
%cn | Committer name |
%ce | Committer email |
%cd | Committer date |
%cr | Committer date, relative |
%s | Subject |
git log --graph
- show commit history in graph viewgit log --since=2.weeks
- limiting git log output to certain timegit log -S function_name
- show all cahnges that changes thefunction_name
word-
git log -- path/to/file
- show commits which changes the file or path provided -
git commit --ammend
- fix the last commit message, file added to staging area will also be commited in this commit -
git reset HEAD <file>
- remove the file from the staging area