→ Get a worksheet with exercises, solutions and a command summary here: GIT_Command_Summary_GERMAN.zip (GERMAN LANGUAGE).
Update local master
git rebase upstream/master # rebase-method (recommended, because commit-graph will be cleaner) or git pull upstream master # merge-method '--force' (if you want to dismiss local changes) |
If there is a new incoming ticket you need to checkout an extra branch for this job.
mle@NB170920MLE MINGW64 /c/Taskana/taskana (master) $ mle@NB170920MLE MINGW64 /c/Taskana/taskana (master) $git checkout -b TSK-45 mle@NB170920MLE MINGW64 /c/Taskana/taskana (TSK-45) $ |
git status |
This command will print all current changes.
git add . # Adding ALL changes git add /src/java/.... # Add only this file git checkout . # remove all uncomitted changes git checkout /src/... # remove changes at this file or untrack it again. |
After finishing the current ticket all new commits should be squashed together.
git rebase -i HEAD~X # X = count of commits you want to summarise |
→ Upcoming example used X=4 for squashing 4 commits into 1.
Now you need to change "pick" into squash(s) to apply changes into next picked commit.
All 3 marked commits will be merged into the picked one. So now there is only 1 commit for this example.
Previous commit-massages can be changed if you want to.
So commits like "TEMP" or "ZWISCHENSTAND" can be deleted/changed.
After squashing your commit into only 1 you need to update and rebase it against the current UPSTREAM/MASTER (or HEAD).
This will keep the graph clean and there will be no confusing problems later.
git rebase upstream/master # rebase it for comparing and order commits. |
git diff --name-only --diff-filter=U # show only files with conflicts |
If you want to update a pull-request you just need to push your branch again.
Maybe push --force ... needs to be used, because squashed commits are not recognized as a newer version.
Workflow for integrating a pull-request.
Download the branch which is marked for pull-request
git fetch upstream pull/<#PULL_REQUEST_ID>/head:<BRANCHNAME> |
Checkout to the new downloaded branch
Checkout back to your master
Merge the branch into master (rebase again optional)
git merge <BRANCHNAME> |
git log # showing logs with meta-data, escape with 'q' git log --graph # showing logs with commit-graph git log --one-line # only first line of commit-messages without any other meta-data - very short overview git log --graph --one-line # showing commit-graph with 1 lone commit-messsage # Add it as short alias git config --global alias.lg 'log --graph --one-line' # without GIT! git lg # showing commit-graph with 1 lone commit-message |
This command can be used to see the current git-graph, which should be only 1 line after merging.
Maybe your current branch crashed or you can´t fix the merge-conflicts with the current upstream/master, then you can pick a commit from another branch (A)
and copy it ontop of another one (B).
This process called and can be done by cherry-picking.
→ Using this command is just a custom selective way to apply single commits and just should be done locally.
→ You need to solve conflicts the normal way if there are some occurring.
git cherry-pick <COMMIT-HASH> # apply commit on top of current branch. |
First you need to get the short or long hash of the commit you want to pick. This can be done by showing the log at source-branch.
Use log --all, and if you want to clear your history pick them one by one, because you can get the same trouble at the new branch.