<
From version < 5.1 >
edited by cds
on 2012/03/21 19:09
To version < 11.1 >
edited by cds
on 2012/03/22 12:11
>
Change comment: There is no comment for this version

Summary

Details

Page properties
Title
... ... @@ -1,1 +1,1 @@
1 -Version Control: The Git Guide
1 +Using Git
Content
... ... @@ -53,4 +53,118 @@
53 53  If you have already cloned the KIELER repository and are only looking for a way to import it into EGit, follow these steps:
54 54  
55 55  1. Click the button //Add an existing local Git Repository to this view// in the //Git Repositories// view and enter the local path.
56 -1. Right-click the //Working directory// entry in the added repository, select //Import Projects//, //Next//, select the projects that you want in your workspace, //Finish//
56 +1. Right-click the //Working directory// entry in the added repository, select //Import Projects//, //Next//, select the projects that you want in your workspace, //Finish.//
57 +
58 += Updating the Repository =
59 +
60 +Your working copy must be clean before you can merge any updates into it. Therefore, always commit your changes locally before you pull. If you don't want to commit them into the master branch, commit them into a new branch. Note that pulling is the same as fetching remote changes and merging them into your local branch. Since a normal merge operation is involved, this can lead to conflicts, which need to be resolved as described below. Note that pulling always merges the remote changes into your current branch. If that's not what you want, checkout the correct branch first or just do a //fetch//.
61 +
62 +Do one of the following three things:
63 +
64 +* Right-click one of the KIELER projects, then from the //Team// submenu choose //Pull//.
65 +* Right-click the KIELER repository in the //Git Repositories// view and click //Pull//.
66 +* Enter {{code language="none"}}git pull{{/code}} on the command line and refresh your workspace.
67 +
68 += Resolving Conflicts =
69 +
70 +Whenever branches are merged or rebased, conflicts can occur. They can be resolved by adjusting the state of your working copy, marking it as clean, and committing the changes. Conflicted files are modified so they contain both your version and the remote version. Edit them until all conflict areas are clean. In Eclipse this can be done by right-clicking the conflicted files - //Team - Merge Tool//.
71 +
72 +{{warning}}
73 +If you try to pull from a remote repository or merge branches although you have local uncommitted changes, and the merge would affect the same files, Git leaves those files as they are, thus discarding the changes that would be made by the pull or merge operation. As a consequence, committing such a conflicted state would ignore the changes of the merged branch even if the commit graph looks like a regular merge has happened. Therefore keep in mind never to pull or merge with uncommitted changes.
74 +{{/warning}}
75 +
76 +**Taking your version of conflicted files:** {{code language="none"}}git checkout --ours <path>{{/code}}
77 +
78 +**Taking the remote version of conflicted files:** {{code language="none"}}git checkout --theirs <path>{{/code}}
79 +
80 += Committing Changes =
81 +
82 +Git manages changes in two separate steps:
83 +
84 +1. Commit changes to your local repository.
85 +1. Push the commit to the remote repository.
86 +
87 +The first step can be done offline, which is very useful in situations where you don't have an internet connection, but would like to save intermediate development snapshots in the history. You can push multiple commits to the remote repository, which for example means that if you are performing changes that would create broken intermediate states, you can commit any number of snapshots locally and only push the whole bundle of commits after you have reached a state that works again.
88 +
89 +If another developer has pushed changes since the last time you have pulled from the server, your attempt to push your commits online may fail. In this case you need to pull the remote changes before you can push. Never use force pushing! ({{code language="none"}}git push -f{{/code}})
90 +
91 +{{info title="Before you commit anything..."}}
92 +Make sure you have set up your name and email address properly, as described on the [[doc:Configuring Eclipse]] page.
93 +{{/info}}
94 +
95 +== Committing ==
96 +
97 +To commit changes with EGit, do one of the following and select the files you would like to commit:
98 +
99 +* Right-click one of the KIELER projects, and from the //Team// submenu, choose //Commit//.
100 +* Right-click the KIELER repository in the //Git Repositories// view and choose //Commit//.
101 +
102 +To commit your changes on the command line, do the following:
103 +
104 +1. Use {{code language="none"}}git add{{/code}} to select (//stage//) the files you would like to commit (new files as well as modified files).
105 +1. Enter {{code language="none"}}git commit{{/code}} to create a commit from the staged files.
106 +
107 +== Pushing ==
108 +
109 +To push your commits to a remote repository with EGit, do one of the following:
110 +
111 +* Right-click one of the KIELER projects, and from the //Team// submenu, choose //Push to Upstream//.
112 +* Right-click the KIELER repository in the //Git Repositories// view and choose //Push to Upstream//.
113 +
114 +To push your commits on the command line, enter {{code language="none"}}git push{{/code}}.
115 +
116 += Getting Earlier Versions of Files =
117 +
118 +If you want to revert //all// your local changes and get back to the previous repository state, use {{code language="none"}}git reset --hard{{/code}} or the //Reset// item in the EGit context menu. If you only want to revert some specific files, do one of the following:
119 +
120 +* Right click the files, click //Replace With//, click //HEAD Revision//.
121 +* Enter {{code language="none"}}git checkout <path>{{/code}} on the command line.
122 +
123 +By giving a branch, tag, or commit number in {{code language="none"}}git checkout <commit> <path>{{/code}}, you can get to any existing version of the files. If no path is given, {{code language="none"}}git checkout <commit>{{/code}} switches your whole working copy and index to the specified branch, tag, or commit number. If {{code language="none"}}git reset{{/code}} is given a commit number, the current branch is modified to point at the given commit.
124 +
125 +{{warning}}
126 +This is a brute force modification, and you probably won't be able to push the new branch
127 +{{/warning}}
128 +
129 += Cleaning Your Working Directory =
130 +
131 +In case the working directory is messed up with unstaged files, which are not affected by {{code language="none"}}git reset --hard{{/code}}, a clean up is achieved by means of {{code language="none"}}git clean -f{{/code}}. The additional switch {{code language="none"}}-d{{/code}} applies this to directories, respectively. Hence, {{code language="none"}}git reset{{/code}} followed by {{code language="none"}}git clean{{/code}} act like {{code language="none"}}svn revert{{/code}}.
132 +
133 +{{code language="none"}}git clean -X{{/code}} removes only the files that are ignored by Git, that is mainly the .class files generated by the Java compiler. A full rebuild is required afterwards.
134 +
135 += Branching and Merging =
136 +
137 +Branches are used to structure your development and are an essential tool for effective work in the KIELER team. Read the [[doc:Source Code Management]] page if you haven't yet understood what branches are good for.
138 +
139 +== Creating a Branch ==
140 +
141 +Do one of the following:
142 +
143 +* Right-click the KIELER repository in the //Git Repositories// view, click //Switch To//, click //New Branch//.
144 +* On the command line, enter {{code language="none"}}git branch <name>{{/code}}. In this case, the new branch is not active; if you want to activate the new branch while creating it, enter {{code language="none"}}git checkout -b <name>{{/code}}.
145 +
146 +In either case the new branch starts at the current position of your working copy, i.e. it branches from the current branch you are on. In order to branch from a different position, either check out that other branch first or select it as //source ref// in the EGit wizard (on the command line simply type git branch <name> <start_point>).
147 +
148 +== Switching to Another Branch ==
149 +
150 +Do one of the following:
151 +
152 +* Navigate to the branch in the KIELER repository in the //Git Repositories// view, right click it, click //Checkout//.
153 +* On the command-line, enter {{code language="none"}}git checkout <name>{{/code}}.
154 +
155 +Note that your local uncommitted changes are transferred when switching the current branch.
156 +
157 +== Merging Branches ==
158 +
159 +You always merge another branch into the current branch. Therefore you first have to checkout the target branch prior to merging. Then, do one of the following:
160 +
161 +* Navigate to the source branch in the //Git Repositories// view, right-click it, click //Merge.//
162 +* On the command line, enter {{code language="none"}}git merge <source_name>{{/code}}.
163 +
164 +This creates a new //merge commit//, i.e. a commit with two source commits, and the target branch (the one you're currently on) contains all changes that have been done in the source branch (the one selected for merge). The source branch is not modified. A merge is done implicitly when pulling: assuming you're on branch master, the command git pull origin master is the same as git fetch origin followed by git merge origin/master, where origin/master is the remote tracking branch for master.
165 +
166 += Working With Multiple Remote Repositories =
167 +
168 +Gitorious allows the creation of personal server-side clones of the KIELER repository, which is highly encouraged as described on the [[doc:Source Code Management]] page. When working with such clones, it is often necessary to synchronize the different server-side repositories with the local one. Git supports this by allowing to configure multiple //remotes// in the local repository. On the command line this is done simply by entering git remote add <name> <url>, where <name> is an arbitrary local identifier for the remote repository. For example, a remote named origin is automatically created when a local repository clone is created through git clone <url>.
169 +
170 +When you push or pull branches, simply select the remote you wish to interfere with. Pulling is done by git pull <remote> <branch>, and pushing is done by git push <remote> <branch>.
Confluence.Code.ConfluencePageClass[0]
Id
... ... @@ -1,1 +1,1 @@
1 -884793
1 +3604607
URL
... ... @@ -1,1 +1,1 @@
1 -https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/KIELER/pages/884793/Version Control: The Git Guide
1 +https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/KIELER/pages/3604607/Using Git