0% found this document useful (0 votes)
12 views

Git Assignment Sayan

Uploaded by

Sayan Sarkar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Git Assignment Sayan

Uploaded by

Sayan Sarkar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 72

Git Assignment

Name - Sayan Sarkar

Roll - 152402011

Exercise 1 - Prepare Basic Git Environment


1. Prepare 'slideshow' project:
i. Clone it from the link provided by the trainer:
• git clone https://github.com/lsnp/slideshow_.git
ii. Remove '.git' folder from 'slideshow_' directory:
• cd slideshow_; rm -rf .git
iii. Initialize the project in 'slideshow_':
a. git init
b. ls -la
c. git add .
d. git commit -m "Initial commit"
iv. Create a folder for all of your Git projects and make a bare project called 'slideshow.git':
a. mkdir ~/repos
b. cd ~/repos
c. git clone --bare ~/path/to/slideshow_ slideshow.git
v. Create the first working copy of 'slideshow.git', name it 'wc1':
• git clone ~/repos/slideshow.git wc1
vi. Check the status in both repositories, 'wc1' and 'slideshow.git', and analyze the
messages:
a. cd wc1
b. git status
c. cd ~/repos/slideshow.git
d. git status
Exercise 2 - More Working Copies
2. Create another working copy 'wc2' from the bare repository created in the first exercise:
• git clone ~/repos/slideshow.git wc2

Exercise 3 - Daily Routine


3. In 'wc1':
i. Make some order with folders:
• Move all pictures into a new folder (pic):
◦ Use mv and check the repo with status and diff
• Move all JavaScript files into a new folder (js):
◦ Use git mv and check the repo
ii. Analyze the situation – what do you observe?
iii. Add to cache changes from step 1:
• git add .
iv. Check the repo:
• git status
v. Create a new revision:
• git commit -m "Organized files"
vi. Check the repo:
• git status
vii. Send changes to the remote repo:
• git push
viii. Check the repo:
• git status
ix. Add a new file 'logo5.html', copy the file 'logo.html' into it, and change the type of picture
rotation:
• In the first row, all should have 'left'
x. Check the repo (wc1), status, and diff:
• git status
xi. Send changes to the remote repo:
• git push
xii. Check the repo again:
• git status
Exercise 4 - Synchronize with Others
4. Actualize 'wc2' and analyze the messages:
i. git pull
ii. git status
Exercise 5 - Empty Folder, Daily Routine Continued
5. In 'wc2':
i. Create a new empty catalog 'html':
a. Check the status – what happened?
b. Send changes to the remote repository – how?
c. Check the status again
ii. In the 'html' folder, place all files with the extension '.html':
• Check status, but don't commit yet
iii. Create a new file "logo_jq2.js", copy "logo_jq1.js", and change parameters (delay, speed,
timeout) for rotation of type 'slideY':
• Check the repo and analyze the messages
• Send changes to the remote repository
• Check the repo again
iv. Test your project – what are your conclusions?
Exercise 6 - Even More Daily Routine
6. In 'wc1':
i. Cut the 'css' code from 'logo.html', place it in a new file "logo.css", and link it:
• Check the repo and analyze the messages
• Send changes to the remote repo
ii. Actualize 'wc1' and analyze the messages:
• git pull
iii. Send changes to the remote repo:
• git push
Exercise 7 - Time Machine, Stage
7. In 'wc2':
i. Remove "logo5.html", use just rm :
• Check the repo and analyze messages
• Go back ( git checkout , git restore )
ii. Remove "logo5.html" again, but this time use git rm :
• Check the repo and analyze messages
• Go back ( git reset , git checkout , git restore )
iii. Finally remove "logo5.html" and send changes to remote repo
iv. Actualize 'wc' and analyze messages
v. Change the table frame; in file "logo.css", add a solid rectangle:
• Check the repo
• Send changes to remote repo
• Check the repo again
Exercise 8 - Am I Assertive?
8. Make sure that all 'wc's are clean, then provide these changes:
i. In 'wc1':
• Actualize the repo
• Change the table frame to dotted in 'logo.css'
• Check status
• Send changes to remote repo
• Check status
ii. In 'wc2':
• DO NOT actualize the repo (-:
• Check status
• Change the table frame to dashed in 'logo.css'
• Send changes to remote repo
• Check status
• What can we do now? (--:
Exercise 9 - Judge Dredd..
9. Find out who and when created 'logo.css':
• git annotate
• git blame
• git log
Exercise 10 - Mirror, Mirror Who's the Prettiest?
10. Check the differences between versions of 'logo.css':
i. For one revision ( git diff , git show )
ii. Between two revisions from before this file was created
iii. Between two revisions after it appeared
iv. Change the order of revision names in (3) and do the diff again
• Do you have any conclusions?
Exercise 11 - Going Back, Stashing
11. Safe way to keep your temporary changes 'out of view':
i. In 'wc1':
• Show pictures in their default size, comment the CSS rule in 'logo.css' ( /* ... */ )
• Move changes to remote repo
ii. In 'wc2':
• DO NOT actualize it!
• Change the width of pictures to '190px'
• Do not stage changes yet
• Now actualize it
• Hide your changes temporarily ( git stash )
• Check status (what does Git say to you?)
• Actualize it again
• Reapply temporary changes ( git stash apply )
• What can/should you do now? (discussion)
• Test these ways of 'going back':
◦ git checkout <rev> , git checkout master
◦ git checkout <rev> <file name> , cat <file name> , get temporary
changes from stash
◦ git reset HEAD <file name> , git checkout -- <file name> , get last
change from stash
◦ git revert HEAD
◦ git revert HEAD <file name>
• Send changes to remote repo (solve the conflict)
Exercise 12 - Boring History..
12. i. Find out what has changed in the file "logo_jq1.js"
a. In general ( git log )
b. Between two revisions (for example 4 and 7)
c. Between yesterday and today
d. In short version with:
• 7 first characters of SHA1
• One line
• Short comment of revision

ii. Check in a quick way how many commits were made by your user in 'wc1':
• git shortlog
Exercise 13 - Daisy's Diary
13. Look at the changes for "logo.css" from reflog:
i. In general ( git reflog )
ii. For a concrete branch

iii. Clean all reflog ( git reflog expire --all --expire=now )

Exercise 14 - FB Ugliest Girls


14. Binary conflict:
i. In 'wc2':
• Open Gitk ( gitk --all & )
• Change a .png file and stage it
• Check the difference between staged and HEAD
• Send changes to remote repo

ii. In 'wc1' (open another terminal):


• DO NOT actualize it!
• Open another Gitk ( gitk --all & )
• Change a .png file
• Send changes to remote repo (?)
• Pull the upstream ( git pull )
• Resolve conflict:
◦ git checkout --theirs <file>
◦ git add --all
◦ git commit
Exercise 15 - Lazy Deploy
15. Build a new version of the whole project using git archive .
Exercise 16 - Headless Chick
16. Use the time machine and go back to the 'logo.html' in revision 4.
• Check the status and go back to the future
Exercise 17 - Tree Monkeys
(Create 'wc3')

17. In 'wc3', create the branch 'beastFutureEwer' ( git branch , git checkout )
i. In 'beastFutureEwer':
• Change 'logo1.html', go back to 'master' and check status, then switch back to
'beastFutureEwer'
• Stage your changes, go back to 'master' and check status, switch back to
'beastFutureEwer'
• Commit changes, go back to 'master' and check status, switch back to
'beastFutureEwer'
• Watch changes in gitk ( gitk --all & ), push changes (?), pull changes (?)
• Change the height of the picture in 'logo.css' to '150px'
• Commit changes
• Check the history, go back to 'master' and check history again. Any conclusions?
ii. In 'master' apply changes:
• In 'logo.css', change the height to '200px'
• Commit changes
• Add a new row in the table in 'logo1.html' and commit this change, watch it in gitk
(refresh with F5)
• Check the history, send changes to the remote repo
• Watch it again with gitk (F5)
Exercise 18 - Tree Monkeys Continued
18. Combine changes from the main branch with 'beastFutureEwer':
• pwd , git merge
i. Create 3 new branches:
• Start them in 3 different revisions in master
• Have at least 2 revisions in each
• Merge them into master in one step ( git merge )
ii. Create 2 new branches:
• First one starts in master
• Second one starts in the first one
• Merge them into each other in reverse order (two steps)
iii. Reverting a merge:
• Create a simple branch with one revision only and merge it into 'masta'
• Undo it
◦ git log --all --branches --graph
◦ git reflog
◦ gitk --all &
◦ git reset(?)
◦ git revert(?)
iv. Pushing branches:

Exercise 19 - Killing One Stone with Many Birds


19. Git rebase1 (watch changes in gitk --all & ):
i. In 'master', add 3 revisions to 'logo_jq.js'
ii. Create the branch 'lackyLuke' and switch to it ( git checkout -b ):
• Start it from HEAD~2
• Add 3 revisions, each to a different file (logo.html, logo1.html, logo2.html)
iii. Create the branch 'sanchoPancha' and switch to it:
• Start it from HEAD~2
• Add 2 revisions, all to the same file (logo.css), different lines
iv. Rebase branch 'lackyLuke' to 'sanchoPancha'

v. Rebase branch 'master' to 'luckyLuke'


vi. Git rebase2:
a. Create the branch 'mniam' and switch to it:
• git checkout -b mniam
b. Add 3 revisions:
• echo mniam >> logo.html
• git commit -m "mniam" -a
• echo mniam1 >> logo1.html
• git commit -m "mniam1" -a
• echo mniam2 >> logo2.html
• git commit -m "mniam2" -a
c. Watch changes in gitk ( gitk --all & )
d. Go back to 'master' and make 2 revisions:
• git checkout master
• echo mniam3 >> logo.html
• git commit -m "mniam3" -a
• echo mniam4 >> logo1.html
• git commit -m "mniam4" -a
e. Refresh gitk (F5)
f. Rebase branch 'mniam' to 'master':
• git branch
• git branch -a
• git checkout mniam
• git rebase master
• git status
g. Solve the issue.
vii. Comparison of 'merge' and 'rebase':
a. In 'wc1':
• Create branch 'mergy' and commit 3 revisions
• Create branch 'merger' and commit 2 revisions
• Combine those 2 branches with 'merge' (merger into mergy)

b. In 'wc2':
• Do the same two operations as in (1) but use names 'reby' and 'rebaser'
• Combine those 2 branches with 'rebase' (rebaser on top of reby)
c. Use gitk --all & to compare both ways.
viii. Reverting 'rebase':
• git reflog
• git reset

Exercise 20 - Can Git Do Necromancy?


20. Recreate file "logo5.html" in 'wc1':
• git revert?
• git checkout?
• git show?
Exercise 21 - Tagging
21. In one of your 'wc', create tags:
i. v1.0 and pin it to the revision in which catalogs 'pic' and 'js' were made
ii. v1.1 and pin it to the revision in which the catalog 'html' was made
iii. v1.2 and pin it to the revision in which the file 'logo.css' was added
iv. Send tags to remote repo ( git tag )

Exercise 22 - Why Not Use GUIs?


22. Use GUIs to make/observe changes ( gitk , gitgui , tig , IDE plugin):
i. Add a new file to the repo
ii. Move an existing file into a different place
iii. Remove a file from the repo
iv. Make a conflict and solve it
v. Push changes to remote repo

Exercise 23 - Simple Spoiling the Config


23. Connect 'manually' the catalog slideshow_ with the remote slideshow.git and get the
latest changes from the repo ( pull ):
• git remote
• git config -e
ii. Create a new bare repo repos/another.git and source it in 'wc3'.
Exercise 24 - The Cherry on the Cake
24. Cherry-pick:
• Cherry Picking Reference
Exercise 25 - More Plumbing?
25. (git clean, git fsck, git gc, git prune)

25.1. In 'wc1':

• Change logo.html
• Add new file mniam
• Clean working copy
(git clean, git checkout)

25.2. In 'wc2':

• Search for dangling objects (git fsck)


• Look at the changes (git show)
25.3. In 'wc3':

• Create 'detached head' state and make 2 revisions (checkout <rev> )


• Go back to 'master' and search for dangling objects (fsck)
• Clean dangling objects (gc)
• Double check with fsck
25.4. In 'wc1':

• Repeat first 2 steps from 25.3.


• Search for dangling objects with git prune
• Clean dangling objects with git prune
Exercise 26 - Can I Be Lazy bastard with Git?
26. Create aliases:

26a. g (alias for git status , in Linux)


26b. git l (alias for git log --pretty=oneline --abbrev-commit --abbrev=4 -25 )
(use git config )
26c. git save (alias for git add . and git commit )
(manually edit .git/config , git config -e )
Exercise 27 - Uglyfying History
27. Additional revision descriptions:

27a. In 'wc1':

• Add 2 additional comments to a tagged revision


• Show list of comments for that revision
(git notes)

Exercise 28 - Externals
28. (git submodule)
http://training-course-material.com/training/Git_-_Submodules

28.1. (git subtree)


http://training-course-material.com/training/GIT_-Patrick2#Submodules.28con.27t.29.E2.8C.98

Setup the clean example:


cd ~
mkdir s
cd ~/s
mkdir subtr
cd subtr
echo "subtr" > subtr
git init
git add .
git commit -m "subtr example"

cd ~/s
git clone --bare subtr subtr.git
cd ~/s/subtr
git remote add origin ~/s/subtr.git
git push --set-upstream origin master

cd ~/s
mkdir mainproj
cd mainproj
echo "mainproj" > mainproj
git init
git add .
git commit -m "mainproj"

cd ~/s
git clone --bare mainproj mainproj.git
cd ~/s/mainproj
git remote add origin ~/s/mainproj.git
git push --set-upstream origin master

## Include 'subtr' as remote repo and make it "subtree"


git remote add subtrOrig ~\s\subtr.git\
git fetch subtrOrig --no-tags
git checkout -b subtr subtrOrig/master
git checkout master
git read-tree --prefix=sub/ -u subtr
git status
git commit -am "tarball from subtr"

cd ~/s/subtr
echo "ch1 in subtr" >> .\subtr
git commit -am "ch1 in subtr"
git push

cd ~\s\mainproj\
echo "ch 1 in main" >> .\mainproj
git commit -am "ch1 in main"
git checkout subtr
git pull

## Merge changes from the subtree into the main project


git checkout master
git diff-tree -p subtr
git merge --allow-unrelated-histories --squash -s recursive -X subtree=sub subtr
git diff-tree -p subtrOrig/master
Exercise 29 - Slow Motion (No Pull)
29a. In 'wc1':

• Change a file and send changes to remote repo

29b. In 'wc2':

• Get changes from the remote repo, but without using pull
◦ Go to .git/ and look at the content of FETCH_HEAD

29c. Combine changes with the main branch and send them to the remote repo
(git fetch, git merge)
Exercise 30 - No Secrets in Git Objects
30a. In 'wc3':

• Search for all files which have linked 'js' files


They should have rows with both <script> and </script> HTML tags
(git grep)
Exercise 31 - Life After the Death of Wikipedia
31. Don't use Uncle Google and find out how to disable the possibility to
force 'push'

• Use git help

31.1. Same way, add another remote repo in your 'wc1'

• Use git help remote

Exercise 32 - Automatic Bug-Finder


32. (git bisect)

• Git Bisect Documentation


Exercise 33 - Whatever
Ignoring Files ( .gitignore vs .git/info/exclude )

1. In wc2 :
• Edit a .png file in 'Inkscape' and save it as test.svg
• Add test.svg to the tracked list of ignored files ( .gitignore )
• Send changes to the repo.

2. In wc1 :
• Edit the logo1.html file in the gedit program and change all occurrences of 'blindZ' to
'up'
• Do not save changes yet
• Ensure that gedit will automatically back up the file
• Add a copy to the non-traced list of ignored files ( .git/info/exclude )
• Send changes to the repo.

3. Clone the repo into wc3 and compare both ignore paths:
• Edit a .png file in 'Inkscape' and save it as source.svg
• Edit the logo2.html file in gedit and change all rotations to 'down', wait for a backup
• Check the state of wc3 , what can you say?
• Send changes to the repo.
Exercise 34 - Listing Files with Context
34. List files in wc2 that are:

• Deleted
• On the stage
• Ignored
• With additional info about changes in cache
• Use git ls-files
Exercise 35 - Being a Good Pimp with Git
35. Hooks.

1. In wc1 :
• Create a pre-commit hook that checks if the word 'notFixedYet' exists in staged changes
and prevents committing such a change.
• Copy pre-commit.sample into pre-commit in the .git/hooks folder.
• Make sure it is executable.
• Prepare the proper bash code.
• Change logo.css with /* notFixedYet */ .
• Change logo.html and type "Fixed".
• Try to commit with git commit -a .
• Use a simple commit.
• Any conclusions?
• Send changes to the remote repo.
2. In wc2 :
• Update the repo.
• Add /* notFixedYet */ in logo.js .
• Commit changes.
• What can you say?
• Fix it!
35.1. Post-Hook

1. In wc3 :
• Create a post-hook that queries a MySQL database with a simple query
( SELECT * FROM table_name ), but only when someone switches between branches.

Exercise 36 - Continuous Integration


36. CI Basics

1. Create a free account here.


2. Add a new project slideshow_ .
3. Clone it into a local repo ( git clone <url> ).
• Add all files and do an initial commit ( git add . , git commit -m "..." ).
• Push ( git push -u origin ).
4. Make a new issue from 'Exercise 1', point a).
• Solve it, commit, and push.
• Pull it into your local copy.
5. Create a new issue from 'Exercise 17'.
• Try to solve everything in GitLab (no command line at all).

Useful Aliases

alias g='git status'


alias ga='git add -A' # Add all possible changes
alias gf='git diff'
alias gh='git push'
alias gi='git commit -m '
alias gk='gitk --all &'
alias gl='git pull'
alias go='git log --graph --pretty=format:'\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgre

You might also like