Changes for page Git
Last modified by Richard Kreissig on 2025/01/30 12:03
Summary
-
Page properties (1 modified, 0 added, 0 removed)
-
Objects (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -2,11 +2,11 @@ 2 2 3 3 More in-depth Git documentation can be found on the [[official home page>>url:http://git-scm.com/documentation||shape="rect"]], which mentions books, videos, and links to other tutorials and references. Furthermore, the shell command {{code language="none"}}git help{{/code}} lists the most commonly used Git commands, and {{code language="none"}}git help <command>{{/code}} gives very detailed documentation for the specified Git command. 4 4 5 -=== Contents === 5 +==== Contents ==== 6 6 7 7 8 8 9 -{{toc style="circle" maxLevel=" 2"/}}9 +{{toc style="circle" maxLevel="3"/}} 10 10 11 11 = Creating Commits = 12 12 ... ... @@ -132,7 +132,7 @@ 132 132 133 133 = Branching and Merging = 134 134 135 -In the previous section you have created two commits on the default branch, which is named {{code language="none"}}master{{/code}}. Now you will create a new branch and commit there, thus adding complexity to the commit graph. In general, you may create as many local branches as you like, since they are simple to use and can be a great tool to structure your work.135 +In the previous section you have created two commits on the default branch, which is named {{code language="none"}}master{{/code}}. Now you will create a new branch and commit there, thus adding complexity to the commit graph. 136 136 137 137 1. ((( 138 138 Create a branch with name //sketches//: ... ... @@ -563,146 +563,4 @@ 563 563 564 564 [[image:attach:turing-graph-02.png]] 565 565 566 -= Other Useful Commands = 567 - 568 -This section contains optional steps that you don't need to push online, but can be useful for you to learn. 569 - 570 -=== Ignoring Files === 571 - 572 -While working on his Machine, Alan Turing has produced a temporary file {{code language="none"}}experiments.tmp{{/code}}, which he does not want to commit in the repository: 573 - 574 -{{noformat}} 575 -$ git status 576 -# On branch master 577 -# Untracked files: 578 -# (use "git add <file>..." to include in what will be committed) 579 -# 580 -# experiments.tmp 581 -nothing added to commit but untracked files present (use "git add" to track) 582 -{{/noformat}} 583 - 584 -Since the extra mention of that file can make Git's status reports unnecessarily cluttered, Alan wants to ignore it permanently. Help him by adding a {{code language="none"}}.gitignore{{/code}} file to the repository: 585 - 586 -{{noformat}} 587 -$ echo "*.tmp" > .gitignore 588 -$ git add .gitignore 589 -$ git commit -m "added ignore file" 590 -[master 738ce4c] added ignore file 591 - 1 files changed, 1 insertions(+), 0 deletions(-) 592 - create mode 100644 .gitignore 593 -$ git status 594 -# On branch master 595 -# Your branch is ahead of 'origin/master' by 1 commit. 596 -# 597 -nothing to commit (working directory clean) 598 -{{/noformat}} 599 - 600 -Now the experiments.tmp{{code language="none"}}{{/code}} file is not considered when viewing the status. You can add arbitrary file name patterns to the {{code language="none"}}.gitignore{{/code}} file; for example it is a good idea to ignore {{code language="none"}}*.class{{/code}}, which are binary files generated for Java projects. 601 - 602 -=== Discarding Changes === 603 - 604 -While working on his Machine, Alan Turing has made some changes to notes.txt that he later found out to be nonsense: 605 - 606 -{{noformat}} 607 -$ git status 608 -# On branch master 609 -# Changed but not updated: 610 -# (use "git add <file>..." to update what will be committed) 611 -# (use "git checkout -- <file>..." to discard changes in working directory) 612 -# 613 -# modified: notes.txt 614 -# 615 -no changes added to commit (use "git add" and/or "git commit -a") 616 -{{/noformat}} 617 - 618 -Help Alan by restoring the last committed state of that file: 619 - 620 -{{noformat}} 621 -$ git checkout HEAD notes.txt 622 -$ git status 623 -# On branch master 624 -nothing to commit (working directory clean) 625 -{{/noformat}} 626 - 627 -Instead of HEAD, which is the last commit on the current branch, you can also name any other branch or commit hash. In that case you would have to commit the change to make it permanent. While resolving conflicts it is possible to use {{code language="none"}}--theirs{{/code}} or {{code language="none"}}--ours{{/code}} instead of HEAD, which replaces the whole content of the respective file by their version (the one on the remote branch) or our version (the one on the current branch). 628 - 629 -A more brute-force option is using the {{code language="none"}}reset{{/code}} command: 630 - 631 -{{noformat}} 632 -$ git reset --hard 633 -HEAD is now at b58ded7 Merge branch 'master' of git.rtsys.informatik.uni-kiel.de:personal-msp/turing 634 -{{/noformat}} 635 - 636 -This resets //all// changes to the working copy to the head of the current branch, so use it with caution! However, {{code language="none"}}reset{{/code}} does not remove unstaged files. In order to do that in one command, use {{code language="none"}}clean{{/code}}: 637 - 638 -{{noformat}} 639 -$ git status 640 -# On branch master 641 -# Untracked files: 642 -# (use "git add <file>..." to include in what will be committed) 643 -# 644 -# test1.tmp 645 -# test2.tmp 646 -nothing added to commit but untracked files present (use "git add" to track) 647 -$ git clean -f 648 -Removing test1.tmp 649 -Removing test2.tmp 650 -{{/noformat}} 651 - 652 -=== Rebasing === 653 - 654 -Consider the following situation: 655 - 656 -[[image:attach:turing-graph-03.png]] 657 - 658 -If you want to merge the changes made on the {{code language="none"}}master{{/code}} branch into the {{code language="none"}}sketches{{/code}} branch, the normal way is to use the {{code language="none"}}merge{{/code}} command and create a merge commit. However, the {{code language="none"}}rebase{{/code}} command gives an interesting alternative to that: it reapplies all commits done in the current branch starting from a given reference. 659 - 660 -{{noformat}} 661 -$ git rebase master 662 -First, rewinding head to replay your work on top of it... 663 -Applying: added another example 664 -Applying: state transitions 665 -Using index info to reconstruct a base tree... 666 -Falling back to patching base and 3-way merge... 667 -Auto-merging notes.txt 668 -{{/noformat}} 669 - 670 -Afterwards the commit graph looks like this: 671 - 672 -[[image:attach:turing-graph-04.png]] 673 - 674 -The two commits made in {{code language="none"}}sketches{{/code}} are reapplied starting from the head of the {{code language="none"}}master{{/code}} branch. The resulting structure of commits is much cleaner than before. rebase{{code language="none"}}{{/code}} even allows to squeeze multiple commits into one. Note that in this example a merge conflict had to be resolved in the same way as it was done in Section "Branching and Merging"; instead of committing the resolved file, the rebase command is resumed with {{code language="none"}}git rebase --continue{{/code}}. 675 - 676 -{{warning}} 677 -Never rebase a branch that is already pushed online! Due to the structural change the rebased branch is no longer compatible with the previous one, and pushing it will fail, since fast-forward merge is not possible. 678 -{{/warning}} 679 - 680 -=== Tagging === 681 - 682 -Finally Alan Turing has made a great success in the development of his Machine, and he would like to fix that stage as "Milestone 1". Help him by tagging the current state of the project: 683 - 684 -{{noformat}} 685 -$ git tag milestone1 686 -{{/noformat}} 687 - 688 -Then the head of the current branch is stored under the name {{code language="none"}}milestone1{{/code}}, so it can be found very easily at later stages of the project: 689 - 690 -{{noformat}} 691 -$ git tag 692 -milestone1 693 -$ git checkout milestone1 694 -Note: checking out 'milestone1'. 695 - 696 -You are in 'detached HEAD' state. You can look around, make experimental 697 -changes and commit them, and you can discard any commits you make in this 698 -state without impacting any branches by performing another checkout. 699 - 700 -If you want to create a new branch to retain commits you create, you may 701 -do so (now or later) by using -b with the checkout command again. Example: 702 - 703 - git checkout -b new_branch_name 704 - 705 -HEAD is now at 957f686... Merge remote branch 'gitorious/master' 706 -{{/noformat}} 707 - 708 -Tags can also be loaded to the server using the {{code language="none"}}push{{/code}} command. 566 +
- Confluence.Code.ConfluencePageClass[0]
-
- Id
-
... ... @@ -1,1 +1,1 @@ 1 -29821 781 +2982163 - URL
-
... ... @@ -1,1 +1,1 @@ 1 -https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/WS12EclPract/pages/29821 78/Git1 +https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/WS12EclPract/pages/2982163/Git