Monday, January 31, 2022

git notes

 



configuration:

------------------

local -- specific repo(used for a having different project repoes on the machine)


global-- for your user account


system -- for all users logged into the system


git config --global user.name

user.email


global configuration file: ~/.gitconfig


git config --global --list



git config --global color.ui true



configure line endings:

---

#auto carriage return line field..for windows true(while pushing rmemoves carriae return and downloading keeps it) for linux/mac input-->(removes carriage returns)

git config --global core.autocrlf


line endings are different in linux(only line feed) and windows(carriage return and line feed).

so in git, it will show as all lines are changed.



configuring aliases:

--------------

git config --global alias.s "status -s"

git config --global alias.lg "log --oneline --all --graph --decorate" ---> oneline all branches in graph with additional info.




rename a file in git:

-----------

git mv index.html home.htm  (renames and adds to staging)

git add -A ---> add all filles including deletions


delete a file:

---

git rm contact.html (deletes and add to staging)


.gitognore file

-----------

*.log

!special.log


git config --global core.excludesfile ~/.gitignore


git commit -am "message" #adds modified files to staging and commits, not for untracked files



branching

---

git branch search --> creates a new branchh

git checkout search 


git checkout -b search2 --> creates and checkout


fast-forward merge

----

git checkout master

git merge search

git branch -d dearch



no fast forward

---

git merge --no-ff my_account_branch #opens a text editor with merge commit message



---

day 2

-----

git diff --> shows unstaged changes

git diff --staged --> shows staged changes

git diff HEAD --> shows dufferences between working directory and last commit, both staged and unstaged changes


#explain about github.com origin, forking and cloning, pull request with fork and same repo branches. merging a pull request, comments in it.

# Adding multiple origins,



when we create a pull request in github, it will point to branch,not commit. So new commmits will automatically show in pull request, after submitting it.


-------------------------

day 3

------------------



git rebasing: to chnage the starting point of a branch.

from feature2, run

git rebase master --> now featurer 2 starting point chnaged with lastest commits of master


git pull --rebase ---> uupdates content from the remote branch and set the origin point



difference between fetch and pull:

-----

git pull--> fetches the changes and merge them to local branch

remotes/origin/master --> last fetched copy of remote branch

git fetch will fetches the origin master branch and syncs it with remotes/origin/master

can check using: git log[/checkout] origin/master ---> in a detached head anyway

---------

git pull origin master: equavalant to:

git fetch

git checkout master

git merge origin/master

---------------


merge vs rebase in pull:

----------------

let's fetch a new commit from remote branch of master.

Also made an extra change in local master.

now we will be having a divergent history for two commits.

git pull below will do the rebase.:

git pull --rebase


default will do merge.


tags and releases:

---

git tag v1.0.0

git tag -a v1.0.1 -m "this was updated messafe" ---> annotated tag, when ran -->git show , will show who tagged and when tagged.

git log


# tages and releases yet to explain in next class


# github desktop and show undo concepts in it.


----------------------------------------------

any new commit saves in .git/objects/<first two letters of commit>/<remaining characters as file name>


git cat-file -p <commit-short-id>


if not in 2.0 version of git, set below config to push only to your branch as default instead of all branches.

git config --global push.default simple


----------

git checkout <tagname>

git checkout -b rb1.0

git tag -a v1.0.0a -m "quick fix to home page bug"


cherry-pick copies the commit to your branch but will generate as a new sha1 hash 

git checkout rb3

git cherry-pick <commitid>


git cherry-pick -n <cmmitid> ---> add the commit chnages to staging area, not as a new commit


To apply a change to multiple branches:

-----------------

git stash ---> saves the working directory to a separate stash commit..so you can apply changes to different branches.Like adding legal notices,etc

git checkout releae_branch

git stash apply ---> resolve if any merge conflicts..and save the changes in the stash to this branch

finally on master branch where stash created:  git stash pop ---> clears the stash and keeps in working copy and we can commit the working copy.


push a tag to github:

--------------

git push --tags


undo in git

---------

git revert <commitid>---> creates a new commit as exact opposite to the commit selected.




-------------

git commit --amend  ---> adding modification to previous commit only and also updates the message. 


git show <commitid> --> shows the details of files/changes to commit


git reset --soft HEAD~2 --> 2 commits, leaves the files in staging area

--hard --> will blow the complete work away

--mixed (default one) --> blow away the commit but keeps the data in the working area.



reflog --  get data back from history

git reflog --->show historic commit

git reset --hard <commitid>


git cherry-pick <commitid>   ---> brings this to the top of head.


git reset --harf HEAD~1

git checkout -b tmp <commitid>

git checkout tmp

git rebase master


rebase interactive:

----

git rebase -i HEAD~5 --> it opens the editor with commits showing in each line, the last 5. And we can edit the messages of it

change the pick to f in front of any commit, that will be merged with its previous commit.

r will just update the message


No comments:

Post a Comment