GIT PART 1

commands

git init   – initialize git repo
How to track files
git log

git log HEAD

HEAD points to the tip of current branch
git status

stage files

git add filename.ext  -add perticular filegit add .  -add everything

commit filesgit commit  -m “message to be added here”

add modified filesgit add filename.ext
to see what changes made to filename  in working directorygit statuslike(unix- diff)git diff -allgit diff filename.ext  -perticular filegit diff -colorwords filename

red-old versiongreen -new version

to see what changes made to filename  in staging index
git diff –staged

How to delete files

1- to take file out of working directory and give command

git rm filename.ext

2. -directly removegit rm filename.ext
then git commit -m “removed filename”

How to move and rename files

1- do it in working directory and then give git commandfirstFile.txt renamed to primaryFile.txt
git add primaryFile.txtgit rm firstFile.txt
done both changes in staging indexgit statuso/p renamed
Moving files to other location

git mv thirdfile.txt  NewFolder/thirdfile.txt   orgit mv thirdfile.txt  NewFolder/rename.txt

 

Undo changes to working repositorymake changes to working dir file index.html Now we have to revert these changes
git checkout — index.htmlgit status working dir is clean now
Undo changes to Staging indexgit  status
modified resources.html
git reset HEAD resources.html
this commoand will go to tip of branch(HEAD) and undo changes for staging index so upon execution resources.html again comes back to working directory

 
Edit last commited change  git commit -amend
git log -gives logs with SHAgo to perticular changegit checkout SHA code.  for that commit
git -diff
git reset HEAD resources.htmlget checkout resources.html

REVERTING COMMITS

git revert SHACODE
it will ask to change comment
UNDO MANY COMMITSgit reset  — reset HEAD pointer and start recording changes from there
1- soft -does not change staging index or working directory
2- mixed-changes staging index to match repository-does not change working directory
3-  hard-changes staging index and working directory to match repository.