- Create an empty local repository named Master, create a text file example.txt with the single line "initial master", push this repository to a remote server
- Checkout test into local repositories named DeveloperA and DeveloperB
- For DeveloperA create a branch named common_branch, switch on it, push it to the remote server
- For DeveloperB switch on common_branch locally
- For DeveloperB in example.txt change "initial master" to "initial developer b", commit and push common_branch to the remote server
- For DeveloperA in example.txt change "initial master" to "initial developer a", commit this locally
https://stackoverflow.com/questions/8198105/how-does-git-store-files#answer-8198276
- For Master in example.txt change "initial master" to "changed master", commit and push master to the remote server
- For DeveloperB find out what changes are made in master without switching locally on master
- For DeveloperA and DeveloperB make rebase of common_branch on master, resolve conflicts by putting "changed developer a" and "changed developer b", respectively
- For DeveloperA return to the state immediately before rebase resetting on the commit in Reflog, after this make rebase anew
- For DeveloperA push common_branch to the remote server, explain how to do this successfully
- For DeveloperB rebase common_branch on remote common_branch, resolve conflicts, push the result to the remote server
- For DeveloperA switch on the remote branch common_branch, what is wrong?
- For DeveloperA find in Reflog the lost commit and switch on it, returning to the previous state for DeveloperA
- For DeveloperA switch on the remote branch common_branch (with overriding local branch), add a file nottocommit.txt, commit this file, push it
- For DeveloperA change the text in example.txt to "changed developer a", make a commit, push the repository
- For DeveloperB pull the remote repository (safe due to fast-forward)
- For DeveloperB make new branch common_branch_b by taking what was locally before pull, switch on it, perform cherry-picking of all commits excluding committing of nontocommit.txt
- For DeveloperB push common_branch_b to the remote common_branch, switch on this remote common_branch (with overriding local branch)
- What may be wrong, if DeveloperA make pull of common_branch this time? Get the changes made by DeveloperB in the remote repository locally not by pull
https://stackoverflow.com/questions/15316601/in-what-cases-could-git-pull-be-harmful
- For Master change the text in example.txt to "updated master", rename (via git!) example.txt to example2.txt, push to the remote server
- For Master create new folder Folder, add new empty file stub.txt in Folder, add stub.txt to the local repository, make a commit, look at the log
- For Master move (via git!) example2.txt to Folder, commit the result, look at the log
- For Master delete (again via git!) Folder with example2.txt and stub.txt from the repository, squash commits (starting from renaming of example.txt to example2.txt) into a single commit, push the result to the remote server
- For DeveloperA change the text in example.txt to "updated developer a", push it to the remote server
- For DeveloperA merge changes from master into common_branch, resolve conflicts by retaining example.txt, push it to the remote server
- For DeveloperB change example.txt to "updated developer b", commit the result locally, merge common_branch with the remote branch common_branch, resolve conflicts so that the resulting example.txt contains two lines: "updated developer a" and "updated developer b", but not commit the result
https://stackoverflow.com/questions/47089913/merge-commit-vs-normal-commit
- For DeveloperB abort merge by making hard reset to the state immediately before previous merge, make merge from the previous item anew, commit the result without pushing, look at the log
- For DeveloperB make a mixed reset to the state before merge, commit the result, look at the log, push the result to the remote server
- For DeveloperA change example.txt to "modified developer a", commit the result and push it to the remote server without fetching before pushing, explain why push cannot be done even with "Known changes" checked?
- For DeveloperA make a mixed reset to the state before merging with master, commit the result anew, fetch, then push the result to the remote server, what may be wrong with the changes made by DeveloperB?
- For DeveloperB push the result with "Known changes" checked anew to restore the state of the remote branch, for DeveloperA make mixed reset up to the commit common for DeveloperA and DeveloperB, stash changes, pull results with fast-forward only, pop stash and make example.txt contain two lines: "modified developer a" and "updated developer b"
10. Rebase: resolving conflicts in the case of deleted files, why squash is useful for resolving conflicts, ways to do squash
- For DeveloperB change example.txt to "modified developer b", commit it, push to the remote server
- For DeveloperB rebase common_branch on master, resolve conflicts with master by not deleting example.txt
- Suppose the previous step was improper, for DeveloperB switch on the remote common_branch with overriding
- For DeveloperB rebase again common_branch on master, resolve conflicts by taking the version of master (i.e. deleting of example.txt), why we have multiple conflicts? how the number of conflicts may be made less by squashing?
- For DeveloperB abort rebase, squash all the commits ahead of master into a single commit, make rebase anew
- Suppose the number of files to be squashed is too big, for DeveloperB switch again on the remote common_branch with overriding, this time make squash via mixed reset, make rebase anew
- For DeveloperA make rebase on master by picking only the last commit and changing the contents of example.txt to two lines: "modified developer a" and "modified developer b", resolve conflicts by leaving example.txt (this is the way of repairing branches alternative to cherry-picking in the case we need to drop wrong commits ahead of master)
- For DeveloperB push common_branch_b to the remote server, for DeveloperA make fetch
- For DeveloperB delete common_branch_b from the remote server, how to delete common_branch_b from the list of remote repositories for DeveloperA (prune old branches)?
- For Master create an empty file example_added.txt, add it, commit to the local repository, then make soft reset to the revision before committing, look at the state of the file
- For Master commit example_added.txt anew, then make mixed reset to the revision before committing, look at the state of the file, what is the difference with the previous state?
- For Master make mixed reset to the commit preceding deletion of example.txt, explain why example.txt did not appeared in the local folder, recover example.txt by making revert
https://habr.com/post/203282/ https://git-scm.com/book/en/v2/Git-Tools-Reset-Demystified
- For DeveloperB add an empty file nottagged.txt, commit it to the local repository, then mark the commit preceding adding of nottagged.txt by a tag, switch the local branch on this tag, realize that the state of files fully correspond to the desired one
- For DeveloperB add an empty file tagged.txt, commit it to the local repository, then switch to master. What may be with the commit containing tagged.txt (detached commit)? Make a new branch common_branch_tagged pointing to this commit not to lose it
- For DeveloperB delete the created tag using "Browse References"
- For DeveloperB make file example.tmp and make git ignore it
- Make globally via configuration that pull makes only fast-forward merges, this is done by adding the following lines in global .gitconfig:
[pull]
ff = only
https://stackoverflow.com/questions/35296680/how-to-configure-git-pull-ff-only-and-git-merge-no-ff
- Perform all the steps from Section 2 in IntelliJ IDEA, please mind that references given by IntelliJ IDEA in the list from the field "Onto" correspond to heads of local branches, not remote ones. To be sure that you rebase on a remote branch, you should edit this field manually, for instance, use /refs/remotes/origin/master for remote master
https://git-scm.com/book/en/v2/Git-Internals-Git-References
https://stackoverflow.com/questions/29914052/i-cant-understand-the-behaviour-of-git-rebase-onto