2. Git version controller image/svg+xml 2. Git version controller Zidarics Zoltánzamek@vili.pmmf.hu 2020 EmbeddedProgramming 1.Preface 3.make 1.feladat 2. Git version controller Requirements software life cycle tracking secure repository local repository for developers backup handle any number of branches protection against malicious manipulation distributed database, no central repository import / export from cvs and svn command line operation Software lifecycle tracking all versions can be quickly restored snapshot instead of diff Secure repository each project has a .git directory any one below the directory containing the .git directorydirectory to use git commands binary format, the repository is a database all changes checked by checksum (SHA-1)(integrity protection) three states Workingdirectory Stagingarea .git directory(repository) Checkout the project Stage fixes Commit Backup "git archive" command arbitrary branches in zip or tar format backup can be automated Protection against malicious manipulation all modifications are protected by SHA-1 checksum binary format Distributed database, no central repository every repository has all the data Single server architecture Multiple server architecture For developers a local repository "git push/pull" commands local branches may remain (local dump) local branches only on the developer machine git merge, git cherry-pick Manage any number of branches master hotfixes releasebranches develop featurebranches Tag0.1 Tag0.2 Tag1.0 Severebug fixedfor 0.2 Incorporatebugfix indevelop Majorfeature fornext release Feature forfuture release Start ofreleasebranch for1.0 onlybugfixes From this point on,"next release"means the releaseafter 1.0 Time Import / export from cvs and svn git svn clone git svn commit git svn rebase git-cvsimport git-sserver Command line operation 139 command fast, efficient command completion with "tab" key porcelain / plumbing graphical clients (gitk, gitg, egit) Patching create patch patch check patch checking without execution patch execution patch execution from mailbox git format-patch master HEAD~4..HEAD --output-directory /tmp/patches git apply --stat /tmp/patches/00* git apply --check /tmp/patches/00* git apply /tmp/patches/00* git am/tmp/patches/00* Installation apt-get install git gitk git config --global user.name "your name" git config --global user.email "your@email.address" echo "machine gitlab.com login <username> password <pwd>" > ~/.netrc chmod 600 ~/.netrc Basic commands git init git add --all git commit -am "commit message" git status git branch <name of new branch> git merge git push origin master git pull origin master git remote add <remote repository id> <url> Useful commands Git documentation Online tutorial Git tutorial Git tutorial Git tutorial Git cheat sheet Git cheat sheet Git cheat sheet Git cheat sheet Git book Git book in english in hungarian Git oktató Git oktató Git oktató Git oktató Git reference GitHub oktató Gitlab model Repository on Gitlab private: All access is granted to each user individually internal: All logged in users are allowed access public: Everyone is allowed access without logging in Roles in a project master: Project Administrator R / W Rights to All Branches reporter: Limited R / O rights to all branches developer: contributor to the project, with R / O rights for some branches guest: read only user R/O joggal minden branch-ra owner: Creator of the project Case study branches release: tested release version. The source of deployment testing: beta, under test, release source development: each programmer has its own branch Zac is a programmer working on a project masterR/O for Zac hotfixesR/O for Zac TestingR/O for Zac Tag0.1 Tag0.2 Tag1.0 Severebug fixedfor 0.2 Merge request Feature forfuture release Time Zac's branch Feature forfuture release Merge request Merge request Merge request hotfixes: bug fixes only Git / Gitlab Concepts Commit A set of files that are affected by changes made at a given time. Contains a link to the preceding commits. The name SHA1 is a 40 character string that uniquely identifies a given commit.The name is the hash identifier generated from the commit data. The same changes have the same name will result. repository Branch merging The repository is a directory where git stores all changes. The directory name is .git. Within the repository, there may be branches that exist only within the repository. Later branches can be merged (merge) Branches can have several different properties. Remote repositories can have multiple unique branches that can be managed locally.This means that you can pull changes from other branches to merge changes into the current branch. Branches have a parent commit in the repository from which that branch is branched. Onemultiple branches can commit from a commit. A B C master HEAD time git branch hotfixes HEAD A B C master HEAD time A B D master HEAD time C hotfixes git checkout hotfixes A B D master HEAD time C hotfixes git commit -am "..." A B D master HEAD time C hotfixes E git checkout master A B D master HEAD time C hotfixes E git commit -am "..." A B D master HEAD time C hotfixes E F git checkout hotfixes A B D master HEAD time C hotfixes E F git merge hotfixes A B D master HEAD time C hotfixes E F G merge request that user does not have permission to write to a branch time A B D master HEAD C hotfixes E F G Senior programmer Junior programmer merge request private final static int MIN_NAME_LENGTH = 3; private final static short MIN_AGE = 1; private final static short MAX_AGE = 100;private String firstName; private String lastName; privateshort age; @Overridepublic String getFirstName() {return this.firstName; } @Override public void setFirstName(String name) {if (name != null && name.length()>MIN_NAME_LENGTH)this.firstName = name; } @Overridepublic String getLastName() {return this.lastName; } @Override public void setLastName(String name) {if (name != null && name.length()>MIN_NAME_LENGTH)this.lastName = name; } @Overridepublic short getAge() {return this.age; } Layer 1 Override public void setFirstNameif (name != null &&this.firstName } @Overridepublic String getLastNamreturn this.lastNam code review merging by senior programmer Demo Branch deletion git branch -d hotfixes git branch -d can cause an error if the referenced branch is not available from other heads. (there is a link to it) Git allows the -D option to prevent dangling commit from being deleted.Consider using git branch -D git clone https://gitlab.com/Zidarics/testc.git Working with repositories Cloning from a remote repository git clone <remote repository url> creates a new directory in the current directory that matches the name of the project (testc) three protocols can be used: git: //, http: // or https: // Validate changes from the remote repository git fetch origin default remote repository name is origin The name of the local branch remains the same as in the remote repository. The commit, merge or other operation issued on the branch is only the local repositorytouch. Git modifies the remote repository only if explicitly requested by the user. The git fetch [remote-repository-reference] command downloads new commit objects from the remote repositoryand creates or modifies the local repository.The default [remote-repository-reference] name is origin. The local head does not change, adding new commits from the remote repositoryand the modified commit changes, but the head pointer does not move. A B D master HEAD time C origin/master If you want to see the changes immediately on the stage, you must use the pull commandThis will download and merge your changes. git pull origin master The master head moves to the last commit. A B D master HEAD time C origin/master Submit changes to the remote repository The git push command logically does the opposite of the pull command, and sends the changes to the remote server. git push origin master Managing Branches at the Remote Repository creating a new branch on the remote repository is possible with the following commands, if anythey exist locally.Make the remote repository name "origin" and the current local branch name "new-branch". git push origin new-branch git checkout [some-other-branch] git branch -f new-branch origin/new-branch First you need to create a new head in the remote repository and then push the new branch. Switch to another branch Sets <new-branch> to current HEAD, even if <new-branch> already exists.Without the -f option, the git branch will refuse to swap. Assign a remote repository to a local repository To add a new remote repository you need a name for the remoterepository. Then git remote add <shortname> <url> $ git add remote origin https://gitlab.com/Zidarics/testc.git Resolving Merge Conflicts Merge conflict occurs when a competing modification is made to onefile, or one file is being tried by multiple users at the same time or at the same timemodify the same line in a file. zamek@ZamekLenovo:/tmp/version_controlling$ git statusOn branch masterYou have unmerged paths. (fix conflicts and run "git commit") (use "git merge --abort" to abort the merge)Unmerged paths: (use "git add <file>..." to mark resolution) both modified: demo.txtno changes added to commit (use "git add" and/or "git commit -a") zamek@ZamekLenovo:/tmp/version_controlling$ cat demo.txtABC<<<<<<< HEADD=======E>>>>>>> hotfixes It is up to the user to choose between the original or the new stateto stay.You will then need to delete the conflict markers <<<<<<<, =======, >>>>>>> and commit the change.
1
  1. Main
  2. Requirements
  3. Secured repository
  4. Backup
  5. Protection against malicious manipulation
  6. Distributed database, no cental repository
  7. Local repository
  8. Manage any number of branches
  9. Svn/Cvs
  10. Command line operation
  11. patching
  12. Installation
  13. Basic commands
  14. Useful commands
  15. Documentation
  16. Gitlab model
  17. Zac I
  18. Zac II.
  19. Git/Gitlab concepts I.
  20. Git/Gitlab concepts II.
  21. Git/Gitlab concepts III.
  22. Git/Gitlab concepts IV.
  23. Git/Gitlab concepts V.
  24. Delete branch
  25. Working with repositories
  26. Cloning
  27. Assign remote repository to a local repository
  28. Validate changes from the remote repository I.
  29. Validate changes from the remote repository II.
  30. Submit changes to the remote repository
  31. Managing branches at the remote repository
  32. Resolving merge conflicts I.
  33. Resolving merge conflicts II.
  34. next