«back
Initializing a repository
–ls –la (Unix) .git or dir (Window)
Project to start tracking get in folder
git init
file .git in the project is created
config file can be used but do not use others
dot do all or filename in quotes
git add .
git commit –m “message here”
if only modifications not if delete or new file so we can commit without going through stage
it will take all in working dir
git commit –am “message here”
«back
log
will show all the commit
git log
git log help
limit no of commit most recent in log or expressed in a date
git log –n 5
git log ––since=2012-06-15
git log ––until=2012-06-15
git log ––author=“Kamran Nafisspour”
regular expression
git log ––grep=“init”
see all logs summarized
git log ––oneline
«back
Diff
statut working file - staging - repository
git status
to see modification in staging before committing
git diff
to see staged diff compare with repository
git diff ––staged
see diff in dif format one line
git diff ––color–words filename.txt
minus(–) + shit + s + return to get full long line
«back
Delete
Delete file from explorer ,when seeing in staged as delete then to delete in repository
git add/rm filename
then we do regular commit
if we want to delete the file from the folder and adds to stage as delete process and the we do commit after
git rm filename.txt
rename if changed from explorer will need to add new and rem, git will figure is a rename and the we commit.
2nd way ,we can rename from git files and will put it stagged
git mv first_file.txt new_file.txt
move to other place directory firstdir but you can also rename it at same time
git mv first_file.txt firstdir/new_file.txt
«back
checkout
so if we want to get a file from repository back to working dir.
use –– will ensure to stay on current branch
git checkout –– filename.txt
to bring back a file modified that is staged not yet committed file and want unstaged.
the working will still keep the change
git reset HEAD filename.txt
in repository how to undo changes or commits. possible to change the latest commit
bring the modified in stage.
Can be used also if we want to change the message onlyS
git commit –– amend –m “message here”
to bring back a version old version of a file do checkout with the SHA 10 first and it
will bring it into staged and recommit if you want.
git checkout 6ae98716b64286eb1 –– filename.txt
so we could re.commit git commit with message
commit git commit -m “6ae98716b64286eb1 message
here”
or discard by unstaged reset and then checkout by taking latest version in repository.
or unstaged / git reset HEAD filename.txt
checkout / git checkout -- filename.txt
if we want to revert a commit take first 10 SHA. note did not work for me failed maybe becs a texteditor
should pop out
I needed it to recommit normal. ok for simple revert otherwise use cmd merge eg file moved or renamed
git revert f3b8da8c035641a62f67c94ff
we can undo recent commit by moving header and start out from there.
Soft move pointer but not staged and wrk dir use SHA to where ou want to point
git reset ––soft f3b8da8c035641a62f67c94ff
mixed move pointer and changed staged but not wrkg dir.
git reset ––mixed f3b8da8c035641a62f67c94ff
hard reset all including working dir. all the commit afterwards will be lost
git reset ––hard f3b8da8c035641a62f67c94ff
to git remove file from being send to rep n test run f forces only on unstaged items
it will remove it from the working dir caution permanent delete
git clean –n
git clean –f
«back
gitignore
for git to ignore files to be tracked in the repository
a file .gitignore and ensure we commit the file
can use regular expression or *.php or negation !index.php (do not ignore)
ignore a all file in dir assets/videos
github ignore file or
github .gitignore suggestion
ignore file globally not just a project and we have the file be anywhere. Create as a above in user
.gitignore_global and all element to exclude cat file to see
git config ––global core excludesfiles c:/user/kamran/.gitignore_global
geet git to ignore file before .gitignore was created. so we must untracked.
it will delete in my repo, leave copy in wrkg dir . takes it off staging process (rm without cached delete
both)
git rm ––cached filename.txt
«back
Branches
to see branches
git branch
to create branch
git branch newbranch
to switch branches
git checkout branchname
to switch and add a branch at the same time
git checkout –b newbranch
We can compare branch and tree-ish ^ mean the previous commit of that branch
git diff new_feature..shorten_title^
And to see branches that hve the latest commit of other branches.
First checkout in which branch you want to be then
git branch ––merged
to rename a branch –m or ––move
git branch –m oldbranch newbranch
to delete branch –d or ––delete. need to be on a another branch to del.
in case some change uncommitted on branch use capital D
git branch –d branchdelete
Now if we finished our branch project and want to merge to a parent.
so i need to be in the receiver branch to merge so use checkout and type the sending branch
Ensure we have the clean directory-
git merge branchname