Welcome to the git_practice repo!
This is the repo to test if you can fluently use Git & Github!
First fork this repo, and follow the instructions to finish the practice
-
Fork this repo and clone it in your own work space.
All of the following steps are executed in your own repo! -
Run the "main.cpp" file. It will be compiled as an executable binary file and output "Hello World!".
-
Create a new branch called "test" from "master" branch, and go to that "test". Add a new cpp hearder file called "algo.hpp" under the "include" folder. Paste the following code in "algo.hpp" file:
#ifndef _ALGO_H_ #define _ALGO_H_ /** * @brief find the Greatest Common Divisor * @param[in] a: one of the integer * @param[in] b: one of the integer * @return int * @retval the result of gcd */ extern int gcd(int a, int b); #endif
-
Add a new cpp source file called "algo.cpp" under the "src" folder.
Paste the following code in your new file:#include "../include/algo.hpp" /** * @brief find the Greatest Common Divisor * @param[in] a: one of the integer * @param[in] b: one of the integer * @return int * @retval the result of gcd */ int gcd(int a, int b); /** * @brief find the Greatest Common Divisor * @param[in] a: one of the integer * @param[in] b: one of the integer * @return int * @retval the result of gcd */ int gcd(int a, int b) { int r; while (a%b!=0) { r=a%b; a=b; b=r; } return b; }
Upload to GitHub.
-
Create a new branch called "dev" from the "test" branch, and go to that "dev". Delete the branch "test" and update the branch status to Github. In "algo.cpp" file, add the following code after the declaration
int gcd(int a, int b);
:/** * @brief find the Least Common Multiple * @param[in] a: one of the integer * @param[in] b: one of the integer * @return int * @retval the result of lcm */ int lcm(int a,int b);
Add the following code after the end of "algo.cpp" file:
/** * @brief find the Least Common Multiple * @param[in] a: one of the integer * @param[in] b: one of the integer * @return int * @retval the result of lcm */ int lcm(int a, int b) { return a/gcd(a,b)*b; }
Upload to GitHub.
-
Create a branch called "modify_algo" from "dev" branch, and go to the "modify_algo" branch. Rollback to the previous version.
In "algo.cpp" file, add the following code after the declarationint gcd(int a, int b);
:/** * @brief find the Least Common Multiple * @param[in] a: one of the integer * @param[in] b: one of the integer * @return int * @retval the result of lcm */ int lcmm(int a,int b);
Add the following code after the end of "algo.cpp" file:
/** * @brief find the Least Common Multiple * @param[in] a: one of the integer * @param[in] b: one of the integer * @return int * @retval the result of lcm */ int lcmm(int a, int b) { return a/gcd(a,b)*b; } // code from "modify_algo"
Upload to GitHub.
-
At github, create the Pull Request from branch "dev" to branch "master". And then merge it. Do not delete this branch!
-
At github, create the Pull Request from branch "modify_algo" to branch "master". And then merge it. Assume the code that existed in "master" is the right one. Do not delete this branch!
-
At local, go to branch "master", add a new cpp hearder file called "algo.hpp" under the "include" folder.
-
Add a new cpp source file called "algo.cpp" under the "src" folder.
Paste the following code into your new file:#include "../include/algo.hpp" /** * @brief find the Least Common Multiple * @param[in] a: one of the integer * @param[in] b: one of the integer * @return int * @retval the result of lcm */ int lcm(int a,int b); /** * @brief find the Least Common Multiple * @param[in] a: one of the integer * @param[in] b: one of the integer * @return int * @retval the result of lcm */ int lcm(int a, int b) { return a/gcd(a,b)*b; }
-
create a function to output "hello world" at the end of "algo.cpp". Upload to Github with your own understanding.