Git

¡Supera tus tareas y exámenes ahora con Quizwiz!

Help command

git help

Show where HEAD is pointing

$ cat .git/HEAD ref: refs/heads/master

Version of Git running

git --version

Compare two branches to see if all changes have been merged into current branch

$ git branch --merged master * shorten_title ∴ changes in first_branch are NOT in shorten_title >> If master contains all changes in a branch ==> can delete branch without losing any changes

Renaming branches

$ git branch -m first_branch modify_title napst@DESKTOP-7Q12MG7 MINGW64 ~/Desktop/Robotics website (master) $ git branch * master modify_title shorten_title N.B. Git considers a rename the same as a move

View remote repos - Github

$ git remote -v github https://github.com/Napster56/Assignment_Part_1.git (fetch) github https://github.com/Napster56/Assignment_Part_1.git (push) origin https://github.com/Napster56/CP1406-Assignment-1.git (fetch) origin https://github.com/Napster56/CP1406-Assignment-1.git (push)

Remove a file from the staging index

$ git reset HEAD tournaments.html Unstaged changes after reset: M tournaments.html

Undo changes to a commit completely

$ git revert 4c0d413..41653bc 100644

Go to home folder

$ cd ~

Create a branch

$ git branch first_branch >> still on master branch: $ git branch first_branch * master >> asterisk denotes the branch currently checked out >> view branches in heads folder: $ ls -la .git/refs/heads total 2 drwxr-xr-x 1 napst 197609 0 Jul 5 11:41 ./ drwxr-xr-x 1 napst 197609 0 Jul 4 13:22 ../ -rw-r--r-- 1 napst 197609 41 Jul 5 11:41 first_branch -rw-r--r-- 1 napst 197609 41 Jul 4 17:36 master >> Until a commit is made on the new branch, HEAD still on master branch: $ cat .git/HEAD ref: refs/heads/master

Undo changes to a file in the working directory

$ git checkout -- aboutvball.html N.B. The "--" indicates we are checking out a file not a branch

Create a branch and checkout at same time

$ git checkout -b shorten_title Switched to a new branch 'shorten_title' >> view branches in repo: $ git branch first_branch master * shorten_title >> asterisk denotes the branch currently checked out >> Because HEAD was on first_branch when shorten_title branch was created and checked out; it is on commit 9714a40 in first_branch $ git log --oneline 9714a40 (HEAD -> shorten_title, first_branch) Modify title of index.html 7109b8e (master) Change title dd14adc Add .gitignore file to repo 9d4d600 Add .gitignore file 2d90fce Reverse 8c144786bc9243d1 8c14478 Delete nav 7543704 Changed name in header 6218214 Initial commit >> If you want to branch from master, MUST checkout master before creating branch

wrap long lines of Git diff

$ git config --global core.pager 'less -r' N.B. To exit the pager ==> type q for quit or h for help

display changes side by side in Git diff

$ git diff --color-words index.html

Comparing branches ==> diff command

$ git diff master..first_branch diff --git a/index.html b/index.html index 00b5190..c84c23c 100644 --- a/index.html +++ b/index.html @@ -9,7 +9,7 @@ <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <!-- Compiled and minified CSS --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css"> - <title>JCU Cairns Robotics Club</title> + <title>JCU Cairns Robotics Club: Smithfield Campus</title> <style> header{ background: url(img/robot.jpg); >> the '.." between the branch names is the range operator >> Use color-words to show what changed on one line:' $ git diff --color-words master..first_branch diff --git a/index.html b/index.html index 00b5190..c84c23c 100644 --- a/index.html +++ b/index.html @@ -9,7 +9,7 @@ <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <!-- Compiled and minified CSS --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css"> <title>JCU Cairns Robotics Club</title>Club: Smithfield Campus</title> <style> header{ background: url(img/robot.jpg);

Git log filter by user name

$ git log --author="Napster" commit a530ba4bc262a46edff6c74ad2a85e15a3748459 (HEAD -> master) Author: Napster <[email protected]> Date: Tue Jul 3 14:04:20 2018 +1000 Delete nav commit 7497c132d22a29df37909fb7c66278e207182ef5 Author: Napster <[email protected]> Date: Tue Jul 3 14:02:28 2018 +1000 Delete navbar commit 17f9864939003341055e1fca886d186ca78cd052 Author: Napster <[email protected]> Date: Tue Jul 3 13:54:54 2018 +1000 Modify file nav

Git log format command

$ git log --format=oneline a530ba4bc262a46edff6c74ad2a85e15a3748459 (HEAD -> master) Delete nav 7497c132d22a29df37909fb7c66278e207182ef5 Delete navbar 17f9864939003341055e1fca886d186ca78cd052 Modify file nav a4e6ca9d85e09f21db8959ec9647cebc93a50e2a Revert to previos version 52def5b27d6af4ef0eb40a264d5db3a4f3bb39c8 Add navbar 30db66a73d87eaa6073699f24c71b837a64f84d7 Rename aboutvolleyball.html to aboutvball.html 5a753abb5907d38accd31884795883f5e8599306 Rename aboutvolleyball.html to aboutvball.html $ git log --format=short $ git log --format=medium $ git log --format=full $ git log --format=fuller $ git log --format=fuller commit a530ba4bc262a46edff6c74ad2a85e15a3748459 (HEAD -> master) Author: Napster <[email protected]> AuthorDate: Tue Jul 3 14:04:20 2018 +1000 Commit: Napster <[email protected]> CommitDate: Tue Jul 3 14:04:20 2018 +1000 Delete nav

View HEAD in all three branches

$ git log --graph --oneline --decorate --all * 85c2f00 (shorten_title) Shorten the title of index.html * 9714a40 (HEAD -> first_branch) Modify title of index.html * 7109b8e (master) Change title * dd14adc Add .gitignore file to repo * 9d4d600 Add .gitignore file * 2d90fce Reverse 8c144786bc9243d1 * 8c14478 Delete nav * 7543704 Changed name in header * 6218214 Initial commit

Git log filter by timeframes

$ git log --since="2018-07-02" commit a530ba4bc262a46edff6c74ad2a85e15a3748459 (HEAD -> master) Author: Napster <[email protected]> Date: Tue Jul 3 14:04:20 2018 +1000 Delete nav commit 7497c132d22a29df37909fb7c66278e207182ef5 Author: Napster <[email protected]> Date: Tue Jul 3 14:02:28 2018 +1000 Delete navbar commit 17f9864939003341055e1fca886d186ca78cd052 Author: Napster <[email protected]> Date: Tue Jul 3 13:54:54 2018 +1000 Modify file nav $ git log --before="2018-07-01" $ git log --since="2 weeks ago" $ git log --since="2 weeks ago" --until="3 days ago"

Git log view all changes

$ git log -p commit a530ba4bc262a46edff6c74ad2a85e15a3748459 (HEAD -> master) Author: Napster <[email protected]> Date: Tue Jul 3 14:04:20 2018 +1000 Delete nav diff --git a/tournaments.html b/tournaments.html index e1d74c8..4d83b66 100644 --- a/tournaments.html +++ b/tournaments.html @@ -18,9 +18,9 @@ height="200"/></a> <h1>Spammers Beach Volleyball - Fitness & Fun, All in One</h1> <nav class="nav"> - <a href="index.html">Home</a> | + <a href="index.html">Home</a> | + <a href="joinus.html">Join Us</a> | <a href="whocanplay.html">Who can play?</a> | - <a href="joinus.html">Join Us</a> | <a href="abouvball.html">About Volleyball</a> | <a href="tournaments.html">Tournaments</a> </nav>

Git log view all changes by file

$ git log -p index.html commit 30db66a73d87eaa6073699f24c71b837a64f84d7 Author: Napster <[email protected]> Date: Sun Jul 1 15:38:14 2018 +1000 Rename aboutvolleyball.html to aboutvball.html diff --git a/index.html b/index.html index 9131ea2..90c5e38 100644 --- a/index.html +++ b/index.html @@ -21,7 +21,7 @@ <a href="index.html">Home</a> | <a href="joinus.html">Join Us</a> | <a href="whocanplay.html">Who can play?</a> | - <a href="aboutvolleyball.html">About Volleyball</a> | + <a href="abouvball.html">About Volleyball</a> | <a href="tournaments.html">Tournaments</a> </nav> </div>

View changes in commit on branch

$ git show HEAD commit 9714a40ceee2cc19e3294f4cd6952a1e597a3809 (HEAD -> first_branch) Author: Napster <[email protected]> Date: Thu Jul 5 12:04:29 2018 +1000 Modify title of index.html diff --git a/index.html b/index.html index 00b5190..eb1d057 100644 --- a/index.html +++ b/index.html @@ -9,7 +9,7 @@ <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <!-- Compiled and minified CSS --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css"> - <title>JCU Cairns Robotics Club</title> + <title>JCU Cairns Robotics Club - Smithfield Campus</title> <style> header{ background: url(img/robot.jpg);

Removing untracked files

$ git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) Remove1 - Copy (2).txt Remove1 - Copy (3).txt Remove1 - Copy (4).txt Remove1 - Copy (5).txt Remove1 - Copy.txt Remove1.txt nothing added to commit but untracked files present (use "git add" to track) >> Show files that will be removed: $ git clean -n Would remove Remove1 - Copy (2).txt Would remove Remove1 - Copy (3).txt Would remove Remove1 - Copy (4).txt Would remove Remove1 - Copy (5).txt Would remove Remove1 - Copy.txt Would remove Remove1.txt >> To delete files: $ git clean -f Removing Remove1 - Copy (2).txt Removing Remove1 - Copy (3).txt Removing Remove1 - Copy (4).txt Removing Remove1 - Copy (5).txt Removing Remove1 - Copy.txt Removing Remove1.txt >> Files are PERMANENTLY deleted ==> not in recycle bin nor in repo!!!!!!!!!

View files in a repo

$ ls -la total 41 drwxr-xr-x 1 napst 197609 0 Jul 4 15:50 ./ drwxr-xr-x 1 napst 197609 0 Jul 4 13:20 ../ drwxr-xr-x 1 napst 197609 0 Jul 4 15:21 .git/ -rw-r--r-- 1 napst 197609 13 Jul 4 15:50 .gitignore -rw-r--r-- 1 napst 197609 0 Jul 4 15:36 .txt drwxr-xr-x 1 napst 197609 0 Jun 29 14:49 img/ -rw-r--r-- 1 napst 197609 9623 Jul 4 15:02 index.html -rw-r--r-- 1 napst 197609 9068 Jun 29 14:59 join.html

List option ls (dir in Windows)

$ ls -la total 41 drwxr-xr-x 1 napst 197609 0 Jul 4 16:26 ./ drwxr-xr-x 1 napst 197609 0 Jul 4 13:20 ../ drwxr-xr-x 1 napst 197609 0 Jul 4 17:36 .git/ -rw-r--r-- 1 napst 197609 519 Jul 4 16:21 .gitignore drwxr-xr-x 1 napst 197609 0 Jun 29 14:49 img/ -rw-r--r-- 1 napst 197609 9630 Jul 4 17:29 index.html -rw-r--r-- 1 napst 197609 9068 Jun 29 14:59 join.html >> ls = list >>-la = format

Location of .gitconfig file

$ pwd /c/Users/napst napst@DESKTOP-7Q12MG7 MINGW64 ~ $ ls -la total 90897 drwxr-xr-x 1 napst 197609 0 Jul 1 12:01 ./ drwxr-xr-x 1 napst 197609 0 May 21 01:28 ../ ... drwxr-xr-x 1 napst 197609 0 Mar 29 22:03 .continuum/ drwxr-xr-x 1 napst 197609 0 Jun 25 19:58 .dotnet/ -rw-r--r-- 1 napst 197609 115 Jul 1 12:01 .gitconfig

Current working directory

$ pwd /c/Users/napst/Desktop/Git_project

Create a file ==> touch command

$ touch .bash_profile

delete files from repo

1. Delete file from File Explorer - file is in the Recycle Bin - Then commit to delete from the repo 2. $ git rm Test4.txt rm 'Test4.txt' napst@DESKTOP-7Q12MG7 MINGW64 ~/Desktop/Git_project (master) $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) deleted: Test4.txt Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) deleted: Test5.txt N.B. Using UNIX delete ==> no file in Recycle Bin

move & rename files in repo using mv command

1. Rename file in File Explorer: - then add newly named file to staging index & remove old file name - then commit changes to repo $ git mv Test2.txt Seconary.txt napst@DESKTOP-7Q12MG7 MINGW64 ~/Desktop/Git_project (master) $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) renamed: Test.txt -> Primary.txt renamed: Test2.txt -> Seconary.txt 2. Using Git: $ git mv Test3.txt New_directory/Test3.txt napst@DESKTOP-7Q12MG7 MINGW64 ~/Desktop/Git_project (master) $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) renamed: Test3.txt -> New_directory/Test3.txt renamed: Test.txt -> Primary.txt renamed: Test2.txt -> Seconary.txt

create .bash_profile

1. Start up Terminal. 2. Type "cd ~/" to go to your home folder. 3. Type "touch .bash_profile" to create your new file. 4. Edit .bash_profile with your favorite editor (or you can just type "open -e .bash_profile" to open it in TextEdit.

Open text editor in Git

> Open .gitignore in $ nano .gitignore

Git repository

>> A Git repository is the .git/ folder inside a project. >> This repository tracks all changes made to files in your project, building a history over time. >> Meaning, if you delete the .git/ folder, then you delete your project's history.

Branch ==> tree-ish

>> A branch is a tree-ish object >> Can compare ancestors: $ git diff --color-words first_branch..shorten_title^ diff --git a/index.html b/index.html index c84c23c..eb1d057 100644 --- a/index.html +++ b/index.html @@ -9,7 +9,7 @@ <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <!-- Compiled and minified CSS --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css"> <title>JCU Cairns Robotics Club:Club - Smithfield Campus</title> <style> header{ background: url(img/robot.jpg); >> The caret = ^ = circumflex

merging branches

>> BEFORE merging changes from a branch into master (or receiving branch), ALWAYS have a clean working directory ==> NO UNCOMMITTED changes 1. checkout master (or receiving branch) 2. merge branch into master (or receiving branch): Robotics website(master) >git merge modify_title Updating 7109b8e..7276d71 Fast-forward index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) >> view merge details: Robotics website(master) >git log commit 7276d7123b327a6458e44a4c6f3fcd9c6517ef30 (HEAD -> master, modify_title) Author: Napster <[email protected]> Date: Thu Jul 5 13:34:03 2018 +1000 Swap out - for : in index.html title >> new commit 7276d7123b32 created >> verify there is no diff between master and branch: Robotics website(modify_title) >git diff master..modify_title Robotics website(modify_title) > ==> can delete modify_title

Writing commit messages

>> Best practices: - mesage should say what it is that's different in this version of the code from the previous version: e.g. git commit -m "Initial Commit" e.g. git commit -m "Added hello.html" - short single-line summary (less than 50 characters) - optionally followed by a blank line and a more complete description where there are many changes - limit each line to 72 characters - write commit messages in the present tense, NOT past tense: - "fix bug" or "fixes bug", not "fixed bug" >> bullet points are usually asterisks or hyphens * Add first file to project >> can add "ticket tracking numbers" from bugs or support requests >> develop a shorthand for changes: * [css, js] update CSS file * "bugfix: " * "#38405 - " >> Messages should be descriptive: BAD - "Fix typo" GOOD - "Add missing > in project section of HTML" BAD - "Update login code" GOOD - "Change user authentication to use Blowfish" >> Do not include messages not related to commit: BAD - "Update member report, we should discuss if this is right next week. >> Commit should describe what the problem was, and what is the fix: GOOD - t23094 - Fixes bug in admin logout When an admin logged out of the admin area, they could not log in to the members area because their session[:user_id] was still set to the admin ID. This patch fixes the bug by setting session[:user_id] to nil when any user logs out of any area.

Create .gitignore file

>> Best to create in the command line in Git Bash >> To open a text editor to create a file: $ nano

Amending commits

>> Can only change the last commit ==> the commit that HEAD points to >> Git does not allow changes to previous commits because the hash ID will change ==> data integrity is compromised $ git commit --amend -m"Rearrange navbar" [master e1043b0] Rearrange navbar Date: Sun Jul 1 17:12:04 2018 +1000 1 file changed, 2 insertions(+), 2 deletions(-) >> Use to amend commit message: $ git commit --amend -m"Add navbar" [master 52def5b] Add navbar Date: Sun Jul 1 17:12:04 2018 +1000 1 file changed, 2 insertions(+), 2 deletions(-)

Directory commands

>> Change directory cd ~ cd Desktop/Git_project >> Show user directory dir

Switch to a branch ==> checkout

>> Checking out a branch: $ git checkout first_branch Switched to branch 'first_branch' >> Git branch confirms the switch: $ git branch * first_branch master >> asterisk denotes the branch currently checked out >> HEAD now points to branch: $ cat .git/HEAD ref: refs/heads/first_branch >> commit changes to branch: $ git commit -am"Modify title of index.html" [first_branch 9714a40] Modify title of index.html 1 file changed, 1 insertion(+), 1 deletion(-) >> View commit: $ git log --oneline 9714a40 (HEAD -> first_branch) Modify title of index.html 7109b8e (master) Change title dd14adc Add .gitignore file to repo 9d4d600 Add .gitignore file 2d90fce Reverse 8c144786bc9243d1 8c14478 Delete nav 7543704 Changed name in header 6218214 Initial commit >> checkout master branch: $ git checkout master Switched to branch 'master' >> Change in branch is not in the master; commit ID 9714a40 is not in master: $ git log --oneline 7109b8e (HEAD -> master) Change title dd14adc Add .gitignore file to repo 9d4d600 Add .gitignore file 2d90fce Reverse 8c144786bc9243d1 8c14478 Delete nav 7543704 Changed name in header 6218214 Initial commit

Fast context switching in Git

>> Checking out a different branch swaps all files and folders in the working directory >> Open index.html when master is checked out: <title>JCU Cairns Robotics Club</title> >> Change to title is not in master >> Open index.html when first_branch is checked out: <title>JCU Cairns Robotics Club - Smithfield Campus</title> >> Change to title is in master first_branch

View commits in the three branches

>> Commit was made in shorten_title: $ git log --oneline 85c2f00 (HEAD -> shorten_title) Shorten the title of index.html 9714a40 (first_branch) Modify title of index.html 7109b8e (master) Change title dd14adc Add .gitignore file to repo 9d4d600 Add .gitignore file 2d90fce Reverse 8c144786bc9243d1 8c14478 Delete nav 7543704 Changed name in header 6218214 Initial commit >> checkout first_branch: napst@DESKTOP-7Q12MG7 MINGW64 ~/Desktop/Robotics website (shorten_title) $ git checkout first_branch Switched to branch 'first_branch' >> commit 85c2f00 is not in first_branch: napst@DESKTOP-7Q12MG7 MINGW64 ~/Desktop/Robotics website (first_branch) $ git log --oneline 9714a40 (HEAD -> first_branch) Modify title of index.html 7109b8e (master) Change title dd14adc Add .gitignore file to repo 9d4d600 Add .gitignore file 2d90fce Reverse 8c144786bc9243d1 8c14478 Delete nav 7543704 Changed name in header 6218214 Initial commit >> checkout master: napst@DESKTOP-7Q12MG7 MINGW64 ~/Desktop/Robotics website (first_branch) $ git checkout master Switched to branch 'master' >> commit 85c2f00 is not in master: napst@DESKTOP-7Q12MG7 MINGW64 ~/Desktop/Robotics website (master) $ git log --oneline 7109b8e (HEAD -> master) Change title dd14adc Add .gitignore file to repo 9d4d600 Add .gitignore file 2d90fce Reverse 8c144786bc9243d1 8c14478 Delete nav 7543704 Changed name in header 6218214 Initial commit

Files should be grouped when making commits

>> Commits should be about a single thing >> For example, if you are changing the tours.html page and the contact.html page on a Tour Guide website, then do two separate commits

Comparing commits

>> Compares two directories to show changes between them: $ git diff 2d90fce44fe7a0b90 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..71adb7a --- /dev/null +++ b/.gitignore @@ -0,0 +1,41 @@ +# Ignore files +tempfile.txt +*.zip +*.gz +log/*.log +log/*.log.[0-9] + +# Ignore user-uploaded assets (images, PFDs, videos) +img/*.jpeg* + +#VisualStudioCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + + +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk diff --git a/index.html b/index.html index d1bf8bd..00b5190 100644 --- a/index.html +++ b/index.html @@ -9,7 +9,7 @@ <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <!-- Compiled and minified CSS --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css"> - <title>Deleted Club Name</title> + <title>JCU Cairns Robotics Club</title> >> can be used to show changes in individual file: $ git diff 8c144786bc9243d176ff088 index.html diff --git a/index.html b/index.html index a067418..00b5190 100644 --- a/index.html +++ b/index.html @@ -9,7 +9,7 @@ <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <!-- Compiled and minified CSS --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css"> - <title></title> + <title>JCU Cairns Robotics Club</title> <style> header{ background: url(img/robot.jpg); @@ -45,7 +45,7 @@ <i class="material-icons indigo-text text-darken-4 text-bold">menu</i> </a> <ul class="right hide-on-med-and-down"> - <!-- <li><a href="#photos" class="indigo-text text-darken-4">Robots</a></li> + <li><a href="#photos" class="indigo-text text-darken-4">Robots</a></li> <li><a href="#service" class="indigo-text text-darken-4">Resources</a></li> <li><a href="iframe src="https://docs.google.com/forms/d/e/1FAIpQLScEH2RAj2q_jvdL6B__vECOrNDjMb9SxhE4nR6t1AjrlKYIeA/viewform?embedded=true" width="700" height="520" frameborder="0" marginheight="0" marginwidth="0" class="indigo-text text-darken-4 font-weight: bold">Join</a></li> @@ -60,7 +60,7 @@ <li><a href="#" class="indigo-text text-darken-4">Contact</a></li> </ul> </div> - </nav> --> + </nav> </header> <!-- services / tabs -->

Git log --oneline

>> Displays commits on a single line with initial part of the SHA $ git log --oneline a530ba4 (HEAD -> master) Delete nav 7497c13 Delete navbar 17f9864 Modify file nav a4e6ca9 Revert to previos version 52def5b Add navbar 30db66a Rename aboutvolleyball.html to aboutvball.html 5a753ab Rename aboutvolleyball.html to aboutvball.html >> Can limit the number of commits: $ git log --oneline -3 a530ba4 (HEAD -> master) Delete nav 7497c13 Delete navbar 17f9864 Modify file nav

Referring to commits

>> Each commit represents a change set --> usually more than one file >> Git generates a checksum for each change set: - checksum algorithms convert data into a simple number - same data always produces the same checksum >> data integrity is fundamental to Git >> Git uses SHA-1 (Secure Hash Algorithm 1) hash algorithm to create checksums: - 40 char hexadecimal string, e.g. commit 7086e1b4f65adc600fed45faca3ddaedacc9d4a0 (HEAD -> master) Author: Napster <[email protected]> Date: Sat Jun 30 14:14:25 2018 +1000 Initial commit - SHA value or commit ID is unique to the changes in a particular commit

Advantages of Distributed version control

>> Enables developers to work collaboratively on a project >> Allows sychronisation of code between the different developers by allowing changes in code to be merged into a master version >> Allows users to test changes to their code without losing the original, i.e. adding new features to a working web app >> Revert back to old versions of code >> no need to communicate with a central server: - faster - no network access needed - no single failure point >> encourages participation and "forking" of projects: - developers can work independently - submit change sets for inclusion or rejection

Git log filter by file

>> Filter from commit ID for a file $ git log 17f9864939003.. tournaments.html commit a530ba4bc262a46edff6c74ad2a85e15a3748459 (HEAD -> master) Author: Napster <[email protected]> Date: Tue Jul 3 14:04:20 2018 +1000 Delete nav commit 7497c132d22a29df37909fb7c66278e207182ef5 Author: Napster <[email protected]> Date: Tue Jul 3 14:02:28 2018 +1000 Delete navbar

Git basics

>> Git is a free and open source version control system, originally created by Linus Torvalds in 2005. >> Unlike older centralized version control systems such as SVN and CVS, Git is distributed: every developer has the full history of their code repository locally. >> This makes the initial clone of the repository slower, but subsequent operations such as commit, blame, diff, merge, and log dramatically faster. >> Git also has excellent support for branching, merging, and rewriting repository history, which has lead to many innovative and powerful workflows and tools. >> Pull requests are one such popular tool that allow teams to collaborate on Git branches and efficiently review each others code. >> Git is the most widely used version control system in the world today and is considered the modern standard for software development.

File-tracking system

>> Git is designed to be a file-tracking system; - tracks files - tracks directories it takes to get to files >> Git ignores directories with no files

git reflog

>> Git keeps track of updates to the tip of branches using a mechanism called reference logs, or "reflogs." >> Many Git commands accept a parameter for specifying a reference or "ref", which is a pointer to a commit. >> Common examples include: - git checkout - git reset - git merge >> Reflogs track when Git refs were updated in the local repository. In addition to branch tip reflogs, a special reflog is maintained for the Git stash. >> Reflogs are stored in directories under the local repository's .git directory. git reflog directories can be found at .git/logs/refs/heads/., .git/logs/HEAD, and also .git/logs/refs/stash if the git stash has been used on the repo. >> git reflog will output the HEAD reflog >> a complete reflog of all refs is obtained by executing: git reflog show --all

status command

>> Git status returns the state of your working directory (the location of the repository on your local system) and the staging area (where you prepare a set of changes to add to the project history) and will show any files which have changes and if those changes have been added to the staging area. >> Run this in conjunction with git add and git commit to see exactly what's being included in the next snapshot. $ git status On branch master nothing to commit, working tree clean $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) Untracked files: (use "git add <file>..." to include in what will be committed) $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) Untracked files: (use "git add <file>..." to include in what will be committed) $ git commit -m "Add second file to project" $ git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) Test3.txt nothing added to commit but untracked files present (use "git add" to track)

Where do Git remotes live?

>> Git stores remotes in the .git folder of course, in config: Robotics website(master) > cat .git/config [core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true [remote "origin"] url = https://github.com/Napster56/Robotics-website.git fetch = +refs/heads/*:refs/remotes/origin/*

Github

>> GitHub is a Git repository hosting service, but it adds many of its own features. >> While Git is a command line tool, GitHub provides a Web-based graphical interface. >> It also provides access control and several collaboration features, such as a wikis and basic task management tools for every project.

Github --> gitignore

>> Github has a repo with .gitignore files already written >> URL: https://github.com/github/gitignore >> When creating a repo, you can add a gitignore file to the repository, and you can pick one based on what kind of project you're going to be doing. >> It will pull from the repository of gitignore files in above repo

How Git works

>> Here is a basic overview of how Git works: 1. Create a "repository" (project) with a git hosting tool (like GitHub or Bitbucket) 2. Copy (or clone) the repository to your local machine 3. Add a file to your local repo and "commit" (save) the changes 4. "Push" your changes to your master branch 5. Make a change to your file with a git hosting tool and commit 6. "Pull" the changes to your local machine 7. Create a "branch" (version), make a change, commit the change 8. Open a "pull request" (propose changes to the master branch) 9. "Merge" your branch to the master branch

Distributed version control

>> In a DVCS (such as Git, Mercurial, Bazaar or Darcs), clients don't just check out the latest snapshot of the files; rather, they fully mirror the repository, including its full history. >> Thus, if any server dies, and these systems were collaborating via that server, any of the client repositories can be copied back up to the server to restore it. >> Every clone is really a full backup of all the data. >> different users (or teams of users) maintain their own repositories, instead of working from a central repository >> changes to code are stored as "change sets" or "patches" >> tracks changes, not versions >> change sets can be exchanged between repositories >> No single master repository; just many working copies: - Each with their own combination of change sets

Github repo

>> In order to connect to a Github repository we have to create it first. >> Naming repo: it should probably match the project name on the local repo.

To work with a new project

>> Initialise Git in file folder >>

Git log filter by global regular expression (grep)

>> Limit the commits output to ones with log message that matches the specified pattern (regular expression). $ git log --grep="Modify" commit 17f9864939003341055e1fca886d186ca78cd052 Author: Napster <[email protected]> Date: Tue Jul 3 13:54:54 2018 +1000 Modify file nav

Switching branches with uncommitted changes

>> To avoid losing changes that are uncommitted, Git does not allow you to change branches: $ git status On branch first_branch Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: index.html no changes added to commit (use "git add" and/or "git commit -a") napst@DESKTOP-7Q12MG7 MINGW64 ~/Desktop/Robotics website (first_branch) $ git checkout master error: Your local changes to the following files would be overwritten by checkout: index.html Please commit your changes or stash them before you switch branches. Aborting >> three options: 1. (use "git checkout -- <file>..." to discard changes in working directory) 2. commit changes to the current branch 3. stash the changes for later use

Merge Conflicts

>> Merge conflicts happen when you merge branches that have competing commits, and Git needs your help to decide which changes to incorporate in the final merge. >> Git can often resolve differences between branches and merge them automatically. Usually, the changes are on different lines, or even in different files, which makes the merge simple for computers to understand. >> However, sometimes there are competing changes that Git can't resolve without your help. >> Often, merge conflicts happen when people make different changes to the same line of the same file, or when one person edits a file and another person deletes the same file. >> You must resolve all merge conflicts before you can merge a pull request on GitHub. >> If you have a merge conflict between the compare branch and base branch in your pull request, you can view a list of the files with conflicting changes above the Merge pull request button. >> The Merge pull request button is deactivated until you've resolved all conflicts between the compare branch and base branch.

Renaming a remote

>> Rename a remote connection from <old-name> to <new-name>. git remote rename

Deleting branches

>> SWITCH to the master branch $ git branch -D shorten_title Deleted branch shorten_title (was 85c2f00). >> cannot delete the branch currently checked out: $ git branch -d modify_title error: Cannot delete branch 'modify_title' checked out at 'C:/Users/napst/Desktop/Robotics website' >> Git warns if you try to delete a branch not fully merged: $ git branch -d shorten_title error: The branch 'shorten_title' is not fully merged. If you are sure you want to delete it, run 'git branch -D shorten_title'.

Initialise command

>> Set up folder where Git files are located C:/Users/napst/Desktop/Git_project >> Git init $ git init Initialized empty Git repository in C:/Users/napst/Desktop/Git_project/.git/

Configuring Git

>> System: Program Files\Git\...\gitconfig git config --system >> User: $HOME\.gitconfig git config --global >> Project: my_project/.git/config git config

Commit command

>> Takes the staged snapshot and commits it to the project history. >> Combined with git add, this defines the basic workflow for all Git users. $ git commit -m "message"

Forking, Pull Request and Merge

>> The flagship functionality of GitHub is "forking" - copying a repository from one user's account to another. >> This enables you to take a project that you don't have write access to and modify it under your own account. >> If you make changes you'd like to share, you can send a notification called a "pull request" to the original owner. That user can then, with a click of a button, merge the changes found in your repo with the original repo. These three features - fork, pull request and merge - are what make GitHub so powerful.

git fetch

>> The git fetch command downloads commits, files, and refs from a remote repository into your local repo. >> Fetching is what you do when you want to see what everybody else has been working on. >> It lets you see how the central history has progressed, but it doesn't force you to actually merge the changes into your repository. >> Git isolates fetched content as a from existing local content, it has absolutely no effect on your local development work. >> Fetched content has to be explicitly checked out using the git checkout command. >> This makes fetching a safe way to review commits before integrating them with your local repository.

Commit log

>> The git log command displays committed snapshots. It lets you list the project history, filter it, and search for specific changes. $ git log commit 7086e1b4f65adc600fed45faca3ddaedacc9d4a0 (HEAD -> master) Author: Napster <[email protected]> Date: Sat Jun 30 14:14:25 2018 +1000 Initial commit >> Help page for log $ git help log >> select time frame $ git log --since=2018-06-29 commit 7086e1b4f65adc600fed45faca3ddaedacc9d4a0 (HEAD -> master) Author: Napster <[email protected]> Date: Sat Jun 30 14:14:25 2018 +1000 Initial commit $ git log --until=2018-06-28 returns nothing, because commit was made on 29th >> search by author $ commit log --author="Napster" >> search in commit message field: grep --> global regular expression search $ git log --grep="Init" commit 7086e1b4f65adc600fed45faca3ddaedacc9d4a0 (HEAD -> master) Author: Napster <[email protected]> Date: Sat Jun 30 14:14:25 2018 +1000 Initial commit

git pull

>> The git pull command is used to fetch and download content from a remote repository and immediately update the local repository to match that content. >> Merging remote upstream changes into your local repository is a common task in Git-based collaboration work flows. >> The git pull command is actually a combination of two other commands, git fetch followed by git merge. >> In the first stage of operation git pull will execute a git fetch scoped to the local branch that HEAD is pointed at. >> Once the content is downloaded, git pull will enter a merge workflow. >> A new merge commit will be-created and HEAD updated to point at the new commit.

git-push

>> The git push command is used to upload local repository content to a remote repository, e.g. GitHub. >> Pushing is how you transfer commits from your local repository to a remote repo. N.B. When we do pushes what we are pushing is a branch >> We are on a branch, and we're telling GitHub push this branch up to the corresponding branch on the remote server.

git reset

>> The git reset command is a complex and versatile tool for undoing changes. >> It has three primary forms of invocation. These forms correspond to command line arguments: --soft, --mixed, --hard. >> The three arguments each correspond to Git's three internal state management mechanism's, The Commit Tree (HEAD), The Staging Index, and The Working Directory. ***** Reset only affects the local repository; it does NOT change the remote (GitHUB) repository. *****

Globally ignoring files

>> This is useful for OS files or the same files that we are ignoring in many different repos ==> ignore files in all repos ==> settings not tracked in repos ==> user-specific, not repository-specific

How to resolve Merge Conflicts

>> To resolve a merge conflict, you must manually edit the conflicted file to select the changes that you want to keep in the final merge. >> There are a couple of different ways to resolve a merge conflict: 1. If your merge conflict is caused by competing line changes, such as when people make different changes to the same line of the same file on different branches in your Git repository, you can resolve it on GitHub using the conflict editor. For more information, see "Resolving a merge conflict on GitHub." 2. For all other types of merge conflicts, you must resolve the merge conflict in a local clone of the repository and push the change to your branch on GitHub. You can use the command line or a tool like GitHub Desktop to push the change. For more information, see "Resolving a merge conflict on the command line." >> If you have a merge conflict on the command line, you cannot push your local changes to GitHub until you resolve the merge conflict locally on your computer. >> If you try merging branches on the command line that have a merge conflict, you'll get an error message. For more information, see "Resolving a merge conflict using the command line."

Referencing a commit

>> Tree-ish ==> a reference to a commit ==> commit in turn references a tree, i.e. the repo and all its files >> tree-ish: - use the full 40 char SHA-1 hash - short version of the SHA-1 hash ==> at least 4 chars and unambiguous ==> 8 - 10 chars - HEAD pointer ==> points to the tip of the currently checked out branch - branch reference, tag reference - ancestry

Github .ignore files for specific languages

>> URL: https://github.com/github/gitignore

Github .ignore files for applications & OS

>> URL: https://github.com/github/gitignore/tree/master/Global

Branching

>> Use a branch to try out code ==> if code is OK, then merge code back to master >> Branch can be used to isolate features or sections of work ==> collaboration >> While user is on branch, others can still work on the master >> Branches remain in the one working directory >> When a branch is merged to into master, changes in branch are committed to the master >> Can merge changes to other branches as well as master branch >> When a commit is made in a branch, HEAD points to the tip of the branch, not master >> If you switch to master, then HEAD points to the tip of the master branch N.B. branch names should be descriptive >> If working on bugs or tickets, use the ticket number

To escape

>> Use ctrl + c $ echo "export EDITOR='Notepad++' > ~/.bash_profile > qQQQ > > > cs > cd > ^C

Compare 2 commits using SHA-1 hashes

>> Use git diff then hash1..hash2 $ git diff dd14adc..8c14478 diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 71adb7a..0000000 --- a/.gitignore +++ /dev/null @@ -1,41 +0,0 @@ -# Ignore files -tempfile.txt -*.zip -*.gz -log/*.log -log/*.log.[0-9] - -# Ignore user-uploaded assets (images, PFDs, videos) -img/*.jpeg* - -#VisualStudioCode -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json - - -# Windows thumbnail cache files -Thumbs.db -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk diff --git a/index.html b/index.html index d1bf8bd..a067418 100644 --- a/index.html +++ b/index.html @@ -9,7 +9,7 @@ <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <!-- Compiled and minified CSS --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css"> - <title>Deleted Club Name</title> + <title></title> <style> header{ background: url(img/robot.jpg); @@ -45,7 +45,7 @@ <i class="material-icons indigo-text text-darken-4 text-bold">menu</i> </a> <ul class="right hide-on-med-and-down"> - <li><a href="#photos" class="indigo-text text-darken-4">Robots</a></li> + <!-- <li><a href="#photos" class="indigo-text text-darken-4">Robots</a></li> <li><a href="#service" class="indigo-text text-darken-4">Resources</a></li> <li><a href="iframe src="https://docs.google.com/forms/d/e/1FAIpQLScEH2RAj2q_jvdL6B__vECOrNDjMb9SxhE4nR6t1AjrlKYIeA/viewform?embedded=true" width="700" height="520" frameborder="0" marginheight="0" marginwidth="0" class="indigo-text text-darken-4 font-weight: bold">Join</a></li>

Version control

>> Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later.

Show hidden files ( .git etc.)

>> View files in Git_project $ dir -la total 8 drwxr-xr-x 1 napst 197609 0 Jun 30 13:59 . drwxr-xr-x 1 napst 197609 0 Jun 30 12:36 .. drwxr-xr-x 1 napst 197609 0 Jun 30 13:58 .git >> View files in .git $ dir -la .git total 11 drwxr-xr-x 1 napst 197609 0 Jun 30 13:58 . drwxr-xr-x 1 napst 197609 0 Jun 30 13:59 .. -rw-r--r-- 1 napst 197609 130 Jun 30 13:58 config -rw-r--r-- 1 napst 197609 73 Jun 30 13:58 description -rw-r--r-- 1 napst 197609 23 Jun 30 13:58 HEAD drwxr-xr-x 1 napst 197609 0 Jun 30 13:58 hooks drwxr-xr-x 1 napst 197609 0 Jun 30 13:58 info drwxr-xr-x 1 napst 197609 0 Jun 30 13:58 objects drwxr-xr-x 1 napst 197609 0 Jun 30 13:58 refs

View branches in repo

>> Where there is only master branch: $ git branch * master >> Where there is more than one branch: $ git branch first_branch * master >> asterisk denotes the branch currently checked out

diff command

>> command details any changes between working directory and the repo $ git diff diff --git a/Test.txt b/Test.txt index 0c55282..a314ff5 100644 --- a/Test.txt +++ b/Test.txt @@ -6,4 +6,6 @@ This is the second edit to this file. This is the third edit to this file. -This is the fourth edit to this file. \ No newline at end of file +This is the fourth edit to this file. + +What are the changes? \ No newline at end of file >> To view changes in the staging index $ git diff --staged

Retrieving old versions

>> copy part of the SHA ID: $ git checkout 5a753abb59 -- aboutvball.html N.B. The "--" indicates use the current directory, not a branch >> File is moved to staging index: $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: aboutvball.html >> To view the changes: $ git diff --staged diff --git a/aboutvball.html b/aboutvball.html index 4c0d413..41653bc 100644 --- a/aboutvball.html +++ b/aboutvball.html @@ -21,13 +21,13 @@ <a href="index.html">Home</a> | <a href="joinus.html">Join Us</a> | <a href="whocanplay.html">Who can play?</a> | - <a href="abouvball.html">About Volleyball</a> | + <a href="aboutvolleyball.html">About Volleyball</a> | <a href="tournaments.html">Tournaments</a> </nav> </div> <div class="netbackground"> <h2>If You Enjoy Team Sports - Play Volleyball</h2> - <img src="images/spikesmall.jpg" class="imageabouvball" title="Men's Volleyball" alt="Men's volleyball" + <img src="images/spikesmall.jpg" class="imageAboutVolleyball" title="Men's Volleyball" alt="Men's volleyball" width="709" height="496"/> <h4>Popularity</h4> <ul class="list"> >> Finally, commit to revert back to previous version

fast-forward merges vs. real merges

>> fast-forward merge occurs when branch is merged into master (or receiving branch) that has NOT changed ==> NO COMMITS since branch was created ==> Git just moves branch commit to master as HEAD ∴ NO record of the merge!!!!!! >> To force Git to create a merge commit: > git merge --no-ff branch <branch> ==> RECORD of merge exists >> do a merge ONLY if fast-forward is possible: > git merge --ff-only branch <branch>

Ignoring files ==> .gitignore

>> file tells Git which files to use and which to ignore >> Uses very basic regular expressions: * ? [aeiou] [0-9] >> Ignore all .php files: *.php >> negate expression ==> this files will be tracked: ==> index!.php >> ignore all files in a directory with trailing slash: assets/videos/ >> To add comments to the .gitignore file: #This is a comment >> Blank lines are skipped

git reset --hard

>> git reset --hard: Resets the HEAD to the commit you select in both the history, undoes the changes in the index, and undoes the changes in your working directory. >> git reset --hard <commit> >> if you do git reset --hard, followed by a commit hash, then that will reset your whole repository back to that version, whichever version was marked by that commit hash. e.g. git reset 50e04a08c9cc79c8f26e8b026cb9dd56b834b603 >> git reset --hard origin/master >> origin/master refers to the version of the original repository from which this repository was cloned. >> In other words, if I cloned my repository from GitHub then running git reset origin/master is going to reset the contents to my repository back to the version that was originally cloned from GitHub.

git reset --mixed

>> git reset --mixed: Resets the HEAD to the commit you select in both the history and undoes the changes in the index.

git reset --soft

>> git reset --soft: Only resets the HEAD to the commit you select. Works basically the same as git checkout <commit #> but does not create a detached head state.

heads folder is where branches are stored

>> heads folder is where branches are stored: $ ls -la .git/refs/heads total 1 drwxr-xr-x 1 napst 197609 0 Jul 4 17:36 ./ drwxr-xr-x 1 napst 197609 0 Jul 4 13:22 ../ -rw-r--r-- 1 napst 197609 41 Jul 4 17:36 master >> can view where HEAD is pointing: $ cat .git/refs/heads/master 7109b8e5451476a98f4165068c9a89b643315689

Working with Git

>> make changes >> add the changes >> commit changes to the repository with a message

HEAD pointer ==> repo ONLY

>> refers to a specific commit in the repository >> pointer to "tip" of current branch repository >> last state of repository, what was last checked out >> points to the parent of next commit >> HEAD switches between master and branches $ git log HEAD commit 3625c4452801b53df6afc132e40b28cee70485bf (HEAD -> master) Author: Napster <[email protected]> Date: Sat Jun 30 16:05:17 2018 +1000 Add another line to file. commit e438ea0a1938c851c9144bfcbc24b2d37ee51a88 Author: Napster <[email protected]> Date: Sat Jun 30 16:00:47 2018 +1000 Add new line to file commit 7086e1b4f65adc600fed45faca3ddaedacc9d4a0 Author: Napster <[email protected]> Date: Sat Jun 30 14:14:25 2018 +1000 Initial commit

To view a specific commit ==> show command

>> show command details any diif in the commit: $ git show commit 7109b8e5451476a98f4165068c9a89b643315689 (HEAD -> master) Author: Napster <[email protected]> Date: Wed Jul 4 17:36:33 2018 +1000 Change title diff --git a/index.html b/index.html index d1bf8bd..00b5190 100644 --- a/index.html +++ b/index.html @@ -9,7 +9,7 @@ <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <!-- Compiled and minified CSS --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css"> - <title>Deleted Club Name</title> + <title>JCU Cairns Robotics Club</title> <style> header{ background: url(img/robot.jpg); >> Below is example where file is added: $ git show 9d4d600285e5912ad6c3 commit 9d4d600285e5912ad6c3b2c5bf7d1ef1faf93875 Author: Napster <[email protected]> Date: Wed Jul 4 16:07:20 2018 +1000 Add .gitignore file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0a9fcc8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Do Ignore .txt files +*.txt >> >> Below is example where tree-ish of a file (SHA-1 hash) is used to contents of the file: $ git show 00b5190811c684f20dd6 <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <!-- font awesome --> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous"> <!--Import Google Icon Font--> <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <!-- Compiled and minified CSS --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css"> <title>JCU Cairns Robotics Club</title> <style> header{ background: url(

View tree listings

>> show files in repo at present: $ git ls-tree HEAD 100644 blob 71adb7a6e00e035835ebee635f2cbaf620e295b3 .gitignore 040000 tree 1841626d7068ae3a06791fde89b74da242a7d82d img 100644 blob 00b5190811c684f20dd63d42b9a83350af65b567 index.html 100644 blob ab7402e8f1b3342ecd4cca2f126bf3a8a3744ef7 join.html >> show files in a folder in the repo: $ git ls-tree master img/ 100644 blob 5daf19aa1e5d2d1133c3509a7c8f423c562dc150 img/arduino.jpg 100644 blob b8a2700cc1042a629241257543cb0a5e666026ff img/banner.jpg 100644 blob 66f3e0e00987ac4d9d0958d9866ed6781771637f img/banner2.jpg 100644 blob ce68122842d0604e8bb4f12519ae3a9d117e93d7 img/girl-2181709_1920.jpg 100644 blob 42ad2ba3d74fc5870ad9d520e49188b7d6a4bb76 img/hand-3308188.jpg 100644 blob 029ea97abb49e79a163d881d9191d02d01159671 img/pololu.jpg 100644 blob 09e0fbce406669a9d14ea782f2f9a00b484a03fb img/robot.jpg 100644 blob d19ade6d9a84ba9b7e18f37b6132b569f5e7fafe img/robot4.jpg 100644 blob 6eaae482c1ea8f5ac3f980d949416a318fe0c660 img/zumo.jpg >> blob = any type of file >> tree = directory

Create a new file - touch cmd

>> touch <file_name>

Branch

Definition: >> A branch represents an independent line of development. >> Branches serve as an abstraction for theedit/stage/commit process discussed in Git Basics, thefirst module of this series. >> You can think of them as a way to request a brand new working directory, staging area,and project history. >> New commits are recorded in thehistory for the current branch, which results in a fork inthe history of the project.

Add command

Moves changes from the working directory to the staging area. This gives you the opportunity to prepare a snapshot before committing it to the official history. >> to add all changes, prior to making a commit: $ git add . N.B. the (.) command means get all changes from the working directory and add them to the staging index >> to add a specific file: $ git add <filename>

Example of git push

Robotics website(master) > git push -u origin master Counting objects: 62, done. Delta compression using up to 8 threads. Compressing objects: 100% (61/61), done. Writing objects: 100% (62/62), 1.59 MiB | 66.00 KiB/s, done. Total 62 (delta 26), reused 0 (delta 0) remote: Resolving deltas: 100% (26/26), done. To https://github.com/Napster56/Robotics-website.git * [new branch] master -> master Robotics website(master) > git log commit f0810176d708722c568a363b64ba09296db20aae (HEAD -> master, origin/master) Author: Napster <[email protected]> Date: Sat Jul 7 14:42:25 2018 +1000

User directory ~ (tilde)

Robotics website(master) >ls -la ~ total 90011 drwxr-xr-x 1 napst 197609 0 Jul 5 15:33 ./ drwxr-xr-x 1 napst 197609 0 May 21 01:28 ../ drwxr-xr-x 1 napst 197609 0 Feb 28 10:44 .anaconda/ drwxr-xr-x 1 napst 197609 0 Jun 30 10:38 .android/ -rw-r--r-- 1 napst 197609 7237 Jul 5 15:34 .bash_history -rw-r--r-- 1 napst 197609 39 Jul 5 15:37 .bash_profile drwxr-xr-x 1 napst 197609 0 Mar 24 14:54 .conda/ -rw-r--r-- 1 napst 197609 43 May 25 14:41 .condarc drwxr-xr-x 1 napst 197609 0 Mar 29 22:03 .continuum/ drwxr-xr-x 1 napst 197609 0 Jun 25 19:58 .dotnet/ -rw-r--r-- 1 napst 197609 181 Jul 4 18:13 .gitconfig -rw-r--r-- 1 napst 197609 267 Jul 4 17:59 .gitignore_global N.B Tilde ~ = user directory

Adding a remote

To add a new remote, use the git remote add command on the terminal, in the directory your repository is stored at. The git remote add command takes two arguments: 1. A remote name, for example, origin 2. A remote URL, for example, https://github.com/user/repo.git

Removing a remote

Use the git remote rm command to remove a remote URL from your repository. The git remote rm command takes one argument: A remote name, for example, github napst@DESKTOP-7Q12MG7 MINGW64 ~/Desktop/Git_project/CP1406-A1 (master) $ git remote rm github napst@DESKTOP-7Q12MG7 MINGW64 ~/Desktop/Git_project/CP1406-A1 (master) $ git remote -v origin https://github.com/Napster56/CP1406-Assignment-1.git (fetch) origin https://github.com/Napster56/CP1406-Assignment-1.git (push)

Config commands

User name: git config --global user.name "Napster" User email: git config --global user.email "[email protected]" View config file: git config --list git config user.name git config user.email Text editor: git config --global core.editor "notepad++" Use colour in command line: git config --global color.ui true

Fetching a remote

When working with other people's repositories, there are a few basic Git commands to remember: git clone <url> git fetch git merge git pull These commands are very useful when interacting with a remote repository. clone and fetch download remote code from a repository's remote URL to your local computer, merge is used to merge different people's work together with yours, and pull is a combination of fetch and merge. To grab a complete copy of another user's repository, use git clone like this: > git clone https://github.com/USERNAME/REPOSITORY.git # Clones a repository to your computer Refer: https://help.github.com/articles/fetching-a-remote/

Clear the screen in Git Bash

clear or ctrl+l

Git pull usage

git pull >> Fetch the specified remote's copy of the current branch and immediately merge it into the local copy. This is the same as git fetch <remote> followed by git merge origin/<current-branch>. git pull --no-commit >> Similar to the default invocation, fetches the remote content but does not create a new merge commit. git pull --rebase >> Same as the previous pull Instead of using git merge to integrate the remote branch with the local one, use git rebase. git pull --verbose >> Gives verbose output during a pull which displays the content being downloaded and the merge details.

Git push usage

git push <remote> <branch> >> Push the specified branch to <remote>, along with all of the necessary commits and internal objects. >> This creates a local branch in the destination repository. >> To prevent you from overwriting commits, Git won't let you push when it results in a non-fast-forward merge in the destination repository. git push <remote> --all >> git push <remote> --all $ git push Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Delta compression using up to 8 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 311 bytes | 311.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To https://github.com/Napster56/CP2406_Project_Assignment_1.git * [new branch] master -> master

To clear entire command history in Git Bash.

history -c


Conjuntos de estudio relacionados

Biology 2 Lecture Connect HW - Ch. 32 The Evolution and Diversity of Gymnosperms and Angiosperms

View Set

Module 13 - Artificial Intelligence and Automation

View Set

Combustion and Corrosion Reactions

View Set

Forensics- Chapter 6: Fingerprints

View Set

2.07: Alegbra Complex Numbers and 3.02: Work with Polynomials & 3.04 , 4.04

View Set

Marketing an Introduction - Chapter 9, mkt 327 for exam 3 quiz 13, 14, 15, 16, Marketing Chp. 15, 16, 21, Marketing Ch 9 10 12, MKTG 3433 Exam 2 UARK, MGMT 3433 UARK Exam 2, Marketing 3433 Lezon Test 2, MKTG 3433 UARK Test 2, MKTG 3433 Chapters 9,10,...

View Set

Chapters 8 and 9 Mastering Biology

View Set

Cisco Project/Based Learning/ Access WAN Chapter 19,20,21

View Set