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=" 3"/}}9 +{{toc style="circle" maxLevel="2"/}} 10 10 11 11 = Creating Commits = 12 12 ... ... @@ -342,7 +342,8 @@ 342 342 1*. If you don't have an SSH key: use the shell command {{code language="none"}}ssh-keygen{{/code}}, confirm the default destination file {{code language="none"}}~/.ssh/id_rsa{{/code}}, and choose whether to give a passphrase. If you have a passphrase, you need to enter it whenever you use your SSH key for the first time in a session. You can omit the passphrase, but that makes the key less secure. As result, the tool generates a private key {{code language="none"}}~/.ssh/id_rsa{{/code}}, which has to be kept secret, and a public key {{code language="none"}}~/.ssh/id_rsa.pub{{/code}}. 343 343 1. Go to //Projects// → //Create a new project// and call it "personal-<login>", replacing <login> with your own login name. 344 344 1. On the next page, create a repository named "turing" (or select //Add repository// on your project page). 345 -1. Once you are on the repository page, copy the URL shown in //Clone & push urls//. 345 +1. On the repository page, go to //Manage collaborators// → //Add collaborators// and add the user msp. 346 +1. Once you are back on the repository page, copy the URL shown in //Clone & push urls//. 346 346 1. Email the copied URL to [[msp@informatik.uni-kiel.de>>mailto:msp@informatik.uni-kiel.de||shape="rect"]]. This will serve as proof for your work on this tutorial. 347 347 1. ((( 348 348 Transfer your {{code language="none"}}master{{/code}} branch to the new server-side repository. Replace the URL in the following command by the one copied from Gitorious: ... ... @@ -377,7 +377,7 @@ 377 377 $ cd turing2 378 378 {{/noformat}} 379 379 380 -The {{code language="none"}}clone{{/code}} command automatically creates a remote named {{code language="none"}}origin{{/code}} in the new local repository, which is set to the given URL. 381 +The {{code language="none"}}clone{{/code}} command automatically creates a remote named {{code language="none"}}origin{{/code}} in the new local repository, which is set to the given URL. You will use this second clone to simulate another user with access to the repository. 381 381 ))) 382 382 1. Edit the file {{code language="none"}}examples.txt{{/code}} in the new clone ({{code language="none"}}turing2{{/code}}): replace {{code language="none"}}"a"{{/code}} in line 6 by {{code language="none"}}"c"{{/code}} and correct the tape representations in lines 9, 14, and 19 accordingly. Commit the change. 383 383 1. ((( ... ... @@ -544,10 +544,10 @@ 544 544 957f686..b58ded7 master -> master 545 545 {{/noformat}} 546 546 547 -While {{code language="none"}}pull{{/code}} performs a {{code language="none"}}fetch{{/code}} and a {{code language="none"}}merge{{/code}}, {{code language="none"}}push{{/code}} transfers the new merged branch to the server. Note that during the merge operation conflicts can occur. In that case you have to resolve them and commit the changes before you can push. 548 +While {{code language="none"}}pull{{/code}} performs a {{code language="none"}}fetch{{/code}} and a {{code language="none"}}merge{{/code}}, {{code language="none"}}push{{/code}} transfers the new merged branch to the server. Note that during the merge operation conflicts can occur. In that case you have to resolve them and commit the changes before you can push. When used without parameters like shown above, {{code language="none"}}pull{{/code}} lookes in {{code language="none"}}.git/config{{/code}} to determine which branches to pull from which remotes. 548 548 ))) 549 549 1. ((( 550 -In order to check out the {{code language="none"}}sketches{{/code}} branch, which was previously pushed to the server, simply type the following command: 551 +In order to check out the {{code language="none"}}sketches{{/code}} branch locally, which was previously pushed to the server, simply type the following command: 551 551 552 552 {{noformat}} 553 553 $ git checkout sketches ... ... @@ -555,7 +555,7 @@ 555 555 Switched to a new branch 'sketches' 556 556 {{/noformat}} 557 557 558 -This branch can be pushed and pulled with the server in the same way as you did for the {{code language="none"}}master{{/code}} branch. 559 +This branch can be pushed and pulled with the server in the same way as you did for the {{code language="none"}}master{{/code}} branch. Never check out {{code language="none"}}origin/sketches{{/code}}, since that is a remote tracking branch! 559 559 ))) 560 560 561 561 The {{code language="none"}}master{{/code}} branch should look like this: ... ... @@ -562,4 +562,78 @@ 562 562 563 563 [[image:attach:turing-graph-02.png]] 564 564 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! 637 + 638 +=== Rebasing === 639 + 565 565
- Confluence.Code.ConfluencePageClass[0]
-
- Id
-
... ... @@ -1,1 +1,1 @@ 1 -298215 91 +2982165 - URL
-
... ... @@ -1,1 +1,1 @@ 1 -https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/WS12EclPract/pages/298215 9/Git1 +https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/WS12EclPract/pages/2982165/Git