Basic Terminology And Overview Git Branches And Remotes

Transcription

2/2/17Basic terminology and overview CommitGit branches and remotes Object pointing to a snapshot Named by hash and stored as a tree Commits have parents that point to the previous snapshot BranchLandon CoxFebruary 2, 2017 Pointer to a commit (and its snapshot) e.g., “master” Remote Collection of branches stored on a remote server e.g., a gitlab or github projecthttps://git-scm.com/book/en/v2/Basic terminology and overviewA commit and its tree Commit Object pointing to a snapshot Named by hash and stored as a tree Commits have parents that point to the previous snapshotWhat are these funny hexnumbers? Branch Pointer to a commit (and its snapshot) e.g., “master” Remote Collection of branches stored on a remote server e.g., a gitlab or github project git add README test.rb LICENSE git commit -a -m “Initial commit”1

2/2/17A commit and its treeA commit and its treeWhy will the commit hashchange if I modify a file? git add README test.rb LICENSE git commit -a -m “Initial commit”Commits and their parentsWhat do I need to move from onecommit to another?best git add README test.rb LICENSE git commit -a -m “Initial commit”Basic terminology and overview Commit Object pointing to a snapshot Named by hash and stored as a tree Commits have parents that point to the previous snapshot Branch Pointer to a commit (and its snapshot) e.g., “master” Remote Collection of branches stored on a remote server e.g., a gitlab or github project2

2/2/17A branch and its commit historyTwo branches w/ same commits git branch testingHEAD pointing to master branch git log --oneline --decoratef30ab (HEAD - master, testing) add 34ac2 Fixed bug #1328 - stack overflow 98ca9 The initial commit of my projectHEAD pointing to testing branch git checkout testing3

2/2/17A new commit under testing vi test.rb git commit -a -m “made a change”A new commit under masterChecking out master git checkout masterMerging branchesGiven the diffs I have, can I integrate mytesting changes into master? vi test.rb git commit -a -m “another change”4

2/2/17Merging branches git branch iss53 git checkout iss53Merging branches vi index.html git commit -a -m “added a new footer [issue 53]” git checkout -b iss53Merging branches git checkout master git checkout -b hotfix git commit -a -m “fixed broken link”Merging branches git checkout master git merge hotfix5

2/2/17Merging branches Merging branchesgit branch -d hotfixgit checkout iss53vi index.htmlgit commit -a –m “finished footer [issue 53]”Merging branchesMerging branches Sometimes merges fail due to conflictsMerge commit: specialcommit created from threeway merge Git cannot create the diffs to move one commit to another Often due to multiple changes to the line in a file git merge iss53Auto-merging index.htmlCONFLICT (content): Merge conflict in index.htmlAutomatic merge failed; fix conflicts and then commit theresult. git checkout master git merge iss536

2/2/17Merging branches Sometimes merges fail due to conflicts Sometimes merges fail due to conflicts Git cannot create the diffs to move one commit to another Often due to multiple changes to the line in a file git statusOn branch masterYou have unmerged paths.(fix conflicts and run "git commit")Edit files to manually resolvethe conflict.Unmerged paths:(use "git add file ." to mark resolution)both modified:Merging branches Git cannot create the diffs to move one commit to another Often due to multiple changes to the line in a file HEAD:index.html div id "footer" contact : email.support@github.com /div div id "footer" please contact us at support@github.com /div iss53:index.htmlindex.htmlno changes added to commit (use "git add" and/or "gitcommit -a")Merging branches Sometimes merges fail due to conflictsInside the conflicted file(index.html in example)Merging branches Sometimes merges fail due to conflicts Git cannot create the diffs to move one commit to anotherContent in master branch Often due to multiple changes to the line in(sincea file HEAD pointed to Git cannot create the diffs to move one commit to another Often due to multiple changes to the line in a filemaster during merge) HEAD:index.html div id "footer" contact : email.support@github.com /div div id "footer" please contact us at support@github.com /div iss53:index.htmlContent in iss53 branch div id "footer" please contact us at support@github.com /div Content of conflicted file after manualresolution.(i.e., kept the iss53 content, removed , , and lines)7

2/2/17Merging branchesRebasing branches Sometimes merges fail due to conflicts Git cannot create the diffs to move one commit to another Often due to multiple changes to the line in a file Once conflict has been resolved, add and commit git add index.html git commitBasic terminology and overviewRemote branches Commit Object pointing to a snapshot Named by hash and stored as a tree Commits have parents that point to the previous snapshot Branch“origin” default name of remote repo“master” branch of remote repo Pointer to a commit (and its snapshot) e.g., “master” Remote Collection of branches stored on a remote server e.g., a gitlab or github project8

2/2/17Remote branchesRemote branches“origin” is local name forthis remoteEquivalent commands toclone. mkdir projectcd projectgit initgit remote add origin janedoe@git.ourcompany.com:project.gitgit fetch origingit merge origin/master Remote branchesmkdir projectcd projectgit initgit remote add origin janedoe@git.ourcompany.com:project.gitgit fetch origingit merge origin/masterRemote branchesCan name remote whateveryou want,e.g., “jane”fetch retrieves data forremotemerge remote/branch intolocal repo mkdir projectcd projectgit initgit remote add origin janedoe@git.ourcompany.com:project.gitgit fetch origingit merge origin/master mkdir projectcd projectgit initgit remote add jane janedoe@git.ourcompany.com:project.gitgit fetch janegit merge jane/master9

2/2/17Remote branchesRemote branches“git pull” is shorthand forfetch and merge mkdir projectcd projectgit initgit remote add origin janedoe@git.ourcompany.com:project.gitgit fetch origingit merge origin/master“git pull” is shorthand forfetch and merge Remote branchesRemote branchesNote that because pull merges, itcan lead to conflicts mkdir projectcd projectgit initgit remote add origin janedoe@git.ourcompany.com:project.gitgit pull origin mastermkdir projectcd projectgit initgit remote add origin janedoe@git.ourcompany.com:project.gitgit pull origin master“git remote –v” prints all theremotes you’ve linked mkdir projectcd projectgit initgit remote add origin janedoe@git.ourcompany.com:project.gitgit remote –v10

2/2/17Remote branchesHow to work with your group project“git remote rm” removes aremote mkdir projectcd projectgit initgit remote add origin janedoe@git.ourcompany.com:project.gitgit remote rm origin11

git checkout iss53 vi index.html git commit -a –m “finished footer [issue 53]” Merging branches Merging branches git checkout master git merge iss53 Merge commit: special commit created from three-way merge Merging branches Sometimes merges fail due to conflicts Git