Skip to content

Instantly share code, notes, and snippets.

@Koziolek
Last active July 4, 2017 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Koziolek/e9505fd28de28867d4c4ae85aa5167f4 to your computer and use it in GitHub Desktop.
Save Koziolek/e9505fd28de28867d4c4ae85aa5167f4 to your computer and use it in GitHub Desktop.
## https://gist.github.com/Koziolek/
Duration:
1 hour 20 min
Objectives:
Learn how to rewrite Git history. Practice in parallel work with remote repository. Get acquainted with Git specific commands: cherry-pick, rebase, stash, tag.
Description:
Rewrite Git history by squashing commits together. Use git cherry-pick to take a commit from somewhere else, and "play it back" wherever you are right now. Rebase commits from one branch into another one. Create remote repository, practice in pushing branches to it and cloning it into local repo. Work with tags. Remove remote branches. Stash changes to be able to switch branches, without commiting what you’ve been working on.
Notations:
(*) - commit symbol.
Task:
1. Rewriting Git history
● Reset master branch to (m3) commit.
● Edit index.html as follows:
<body>
First git repo
- Prepare to first merge
+ Prepare to first rebase
</body>
● Add and commit changes (m5).
● For the current master branch, squash two last commits (m3) and (m5) into one commit (m6).
2. Cherry-picking commit
● Apply commit from title-fix branch into master branch.
3. Rebasing
● Switch to js-feature branch.
● Add the following code to index.html:
<head>
<title>Hello gt</title>
+ <script>console.log("hello git!")</script>
</head>
● Add and commit changes (jf1).
● Rebase commits from master branch into js-feature branch.
● Create js-feature-old branch, set branch pointer to (jf1) commit.
4. Working with remote repository
● Create remote repo - remote at github/bitbucket or in file system.
● Push all local branches from Alpha to created repo.
● Clone remote repo into another one local repo (Sigma).
● In Alpha, rollback 3 last commits in js-feature branch and push it to remote repo.
5. Tagging
● In Alpha, add tag to last but one commit in master branch.
● In Sigma, switch to that tag.
6. Removing remote branch
● Remove js-feature-old branch from the remote repo using console.
7. Stashing your work
● In Alpha, add the following code to title-fix:
- <title>Hello git<title>
+ <title>Hello git, goodbye SVN<title>
● Making no commit, switch to master branch.
● Remove style.css file, commit changes.
● Switch back to title-fix branch and commit previously made changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment