Version Control Systems - itzjac/cpplearning GitHub Wiki

Pretty sure I was one of the very few privileges that started working with Perforce (P4) when I just had joined to the game industry in Mexico. The project at the time, organized as a very large code/art team, had P4 exploited to its core. We used customized plugins (3DStudio Max, Photoshop) and also in-house technology that connected to P4. The game itself also had a very centralized and traditional server/client model, as any MMO, the company had the network know how, the money, the facilities, was a solid and capable place maintaining such features 24/7.

P4 has accompanied most of the AAA studios world wide to provide an effective and intuitive platform that supports source code, raw binaries, art assets and integrated plugins for most popular IDE's. Binary files, large files are perfectly supported. Any other third party library or tool, can implement a native P4 plugin, take one step further integrating it into the pipeline.

While you can try/experiment with P4 locally (with very limited users), it is a platform that costs a lot of money. Some small companies can't simply afford the price or is not worth expending money having for "free" the alternatives out there (i.e. git). The companies accept and embrace the sacrifice, probably by decreasing the UX, or forcing the command line usage on each team member.

It really took years to have a strong and free competitor like git, to be considered as a serious alternative and competitor against P4. Partially thanks to the indie scene, widely embracing it for their regular game dev pipelines. Other free options available (Tortoise, Mercury, SVN, ApacheSubversion), are still used by some teams and each one has its own pros/cons, but up until today they were never as popular and accepted. As for the UX in the git, is minimal or unavailable. Bottom line, all your dev team will have to learn console commands. Several attempts to turn git into a good UX platform: SourceTree, git desktop, you name it. It will always be much more flexible and easy to nail down using the command line.

git became the default election by a vast majority of indie studios and reached the entire video game industry. Medium size or AAA are also now using it for internal, small, toy projects or even for the production. No doubt git is a very powerful tool.

In this section, I want to highlight both the pros/cons of each of the two major version control system used world wide in the game industry: git and P4. Want to also give hints, common pitfalls, and try to clarify the confusing terms for people coming from any of version control flavor that needs to switch gears to the other one. When I started learning and using professionally, other version control system available, like TortoiseSVN or git, I always struggle switching to the lingo down to the very core concepts. For instance: P4 is a centralized version control system, git is distributed.

The obvious implications for a centralized system are

  • You must be connected to a server. At all times, when updating your local copy of the repo, when committing changes, when sharing work with other peers. Though there are some mechanism to work offline and recover it once you restore the server connectivity, a hassle
  • You have a copy of the repository. The ultimate truth is only on the server
  • More users connected to the server, will increase the costs
  • Deltas happen in the server, you as the client will have copies of every branch (traditional branches), reason why P4 later added the concepts of streams following closer to the concept of branching in git
  • File READ/WRITE properties are fully supported

I think people coming from distributed version controls, have a hard time understanding this. Yes, there is support for branches, streams, cherry pick, roll backs and more, but it just doesn't work the same. Once you wrap your head around and understand the real meaning of P4 being centralized, server based, it becomes so easy!

The opposite scenario holds true, having worked on a distributed version control system then moving to its centralized alternatives, is not the most intuitive transition. I have plenty of stories at work when explaining to people coming from the different tool. The most broken, ironic, bizarre and stupid discussions I ever had, if only the concepts covered here were really clear.

Git - Distributed version control

Git https://git-scm.com/

SourceTree is probably the best UI interface, it also contains SSH command that was NOT include in old version of the git installation

Notes

Tutorials

Pro Git

Commands and workflow

git pull
mkdir wolf3d
cd wolf3d/
git clone [email protected]:id-Software/wolf3d.git
git clone [email protected]:id-Software/wolf3d.git
git login
git --help
git help -a
git log
cd projects/
cd wolf3d/
git clone [email protected]:id-Software/wolf3d.git
config
git -config 
git -user
git config --global user.name "itzjac"
git config --global user.name 
git clone [email protected]:id-Software/wolf3d.git
ssh -T [email protected]
ssh-agent -s
git config --global 
git config --global credendial.helper wincred
git clone [email protected]:id-Software/wolf3d.git
git config --global user.email [email protected]
git config --list
git config --global user.email [email protected]
git clone [email protected]:id-Software/wolf3d.git
git clone [email protected]:[DavidWells](https://app.assembla.com/wiki/show/c-cprogramming/DavidWells)/isomorphic-react-example.git
ssh-keygen -t rsa -b 4096 -C "[email protected]"
ssh -vT [email protected]
git clone [email protected]:id-Software/wolf3d.git
git clone https://github.com/[AlDanial](https://app.assembla.com/wiki/show/c-cprogramming/AlDanial)/cloc.git
git clone https://github.com/[AlDanial](https://app.assembla.com/wiki/show/c-cprogramming/AlDanial)/cloc.git
mkdir git_playing
cd git_playing/
git clone https://github.com/itzjac/tuna.git
git log
git log
git --version
git --log config
git config
git config --local
git config --system
git config --global
git config --global
git config --global
git config --local
git config   --global
git config  --global
git config --list
git config --list --show-origin 
git config --global user.name
git config --global user.email 
git config --global core.editor emacs
git config --global core.editor "D:\projects\dev\gameprogramming\emacs\emacs.bat --multiInst --nosession"
git config --list
git config user.name
git config --show-origin rerere.autoUpdate
git config --show-origin user.editor
man git-push
emacs .git/config
git add main.cpp 
git add LICENCE
vim LICENCE
git commit -m "initial project version"
git status
dir
git add LICENCE
git commit -m "initial project license"
git status
vim main.cpp 
git status
clear
git status
vim README
git status
git add README 
git status
git add README 
git commit -m "Readme and first changes"
git status
git add
git add .
vim main.cpp 
git status -s
git commit -m "I/O library"
git status -s
git commit -m "Git ignore initial configuration"
git stat
git config --global core.editor 'winpty /c/Program/Emacs/bin/emacs -nw'
git config --local core.editor 'winpty D:\projects\dev\gameprogramming\emacs\emacs.bat -nw'
git config --system core.editor "winpty D:\projects\dev\gameprogramming\emacs\emacs.bat -nw"
git config --global core.editor "winpty D:\projects\dev\gameprogramming\emacs\emacs.bat -nw"
git config --global core.editor emacs
git config --global core.editor "winpty C:\projects\dev\gitplaying\emacs\emacs.bat -nw"
git config --system core.editor "winpty C:\projects\dev\gitplaying\emacs\emacs.bat -nw"
git config --local core.editor "winpty C:\projects\dev\gitplaying\emacs\emacs.bat -nw"
emacs.bat .gitignore 
git config --list
git config --list --system
git config --list --local
git config --list --global
git config --list --local core.editor
git config --list core.editor
git config --list --global core.editor
git config --list --local core.editor
git config --list
git config --global alias.emacs 'emacs.bat'
git config --global --unset alias.emacs
git config --local --unset alias.emacs
git config --system --unset alias.emacs
git config --local alias.status st 
git config --system --unset alias.status
git st

Starting up

Version

git --version

Git set up user/email git config --global user.name "tunafish" git config --global user.email "[email protected]"

Display settings

git config --list
git config
git config user.name

Clear the screen

clear

.. never forget

git help[command]

Creating a project

Move to a path where the project will be stored. Initialize empty git reposity, will create a hidden folder .git. Inside this path, git will be capable of tracking the changes. git init

Working with the project

Change the working copy of the project adding one or more files. Add all those changes to the staging area git add .

Commit the files, save this point in time. End goal, it will push the changes to the repository

git commit -m "MyComments"

Look at the commit history

git log
git log --author="itzjac"

Assuming your branch was created off develop

git cherry -v develop
git log develop..

Look at the current status of the .git repository

git status

Looking at differences between working copy and repository

git diff

By default diff will only compare unstaged files with the repository. It is possible to diff agaisnt staged files using

git diff --staged

Diff untracked files

git diff --no-index a.txt b.txt

Changing configuration

git config core.autocrlf [true/false]

If we want to convert LF -> CRLF or not.

git config --global --edit

Deleting files in working copy and will be added to the staging area

git rm [filename.ext]

This change need to be committed to actually modify and delete the repository.

Renaming a file.

After the rename action has happened git will detect the change as two different actions: delete old file name, add new file name. To have git understand the renaming, two commands are necessary

git add oldfilename.ext
git rm newfilename.ext

the status of git will now report a renamed action

A simple way of renaming in one step

git mv [oldfilename.ext] [newfilename.ext]

Moving file to another folder

git mv [filename.ext] /relative_path/filename.ext

Bulk changes

Put all the changes directly to the staging area, it will grab all the changes , it can be dangerous

git commit -am "Updating bulk files"

Reverting changes, it will take files from the repo and substitute the working copy.

git checkout -- /relative_path/[filename.ext]

Unstage files

git reset HEAD /relative_path/filename.ext

Reverting to a change in time: getting a copy of a previous stamp time and put it to the latest. Let's say we want to revert to the second version on tim first > second > third

The result will be first > second > third > second

git log
git checkout #commit reference number# -- [filename.ext]
git status
git commit -am "Reverting comments"

HINTS: reset HEAD using git checkout master

Remote Server Access

Git keeps track of changes in a project. GitHUB allows you to public projects to the web.

Creating the githHuB project and creates connection to the repository

git remote add nickname https://gitbug.com/userprofile/repo.git

List the nicknames

git remote

To push it all

git push -u nickname master

Later changes to push to the online server, will add files etc.. git push

NOTE: if you forget to add the "master" at the end, an error will occur the current branch master has no upstream branch, "git push --set-upstream tuna master"

Get from the online server

git fetch

Branch

Within the master branch create a new branch based on this one. It will be first locally, then pushed to the server

git checkout -b myNewBranchName
git remote add tuna_minu https://github.com/userprofile/myrepository.git
git push [remoteName] myNewBranchName

To update the branch from the repository, when the branch has been properly checkout

git pull [remoteName] [remoteBranch]

Delete

git branch -d [branchName]

Tutorials

https://www.youtube.com/watch?v=cEGIFZDyszA&list=PL6gx4Cwl9DGAKWClAD_iKpNC0bGHxGhcx&index=1

Perfoce - Centralized version control

Rollback, undoing changes to a changelist number.

image