Skip to content

Git Problems and Fixes

mikejbrown edited this page Sep 30, 2016 · 21 revisions

"Can we create a Git channel here?" - Mizipzor

Use this page for FAQ and problems with using Git and ways how to fix them for others to see and learn.

Quill's Git tutorial

Quill's Updated Git Tutorial

Git Commands

Official Git Documentation

Github resources for learning Git and Github

Pro Git: the official git book, written by Scott Chacon and Ben Straub and published by Apress (free to read online -- dead tree version available for $)

ohshitgit.com


#Git with GUI Many of you would like to skip the command line in order to help with the project.

Here is the solution: Source Tree. It's a simple way to view the project's progress, and it's available for Mac and Windows. [//]: # (removed "only available" because mac and windows are the only OS's that unity supports, so if you don't have either, you can't really contribute to the project at all.)

You'll have to fetch the master from TeamPorcupine (master) and then merge with your local master before you merge your "feature" branch every time you want to push. (I recommend fetch and merge and not straight up pull because if it happens that you are on the wrong branch you wouldn't lose anything). ###!!Tutorial Coming


Troubles with Travis

Now that we have integrated with Travis, there will be times when your Pull Request will fail to build in travis, and will be shamefully marked with a red X for all to see. If your PR failed to build in travis one of the following happened:

  • Your Pull Request has a compilation error
  • Your Pull Request causes a unit test to fail (or you wrote a new unit test that fails)
  • Travis is being dumb <- most likely option

To see which occurred, click on the red x, and show detail so you are taken to the build on travis-ci.org. Read the log output and see what the last few messages are.

  • Results file not found! - you have a compilation error.
  • 1 unit test failed! - your PR breaks a unit test. obviously.
  • No output has been received in the last __ - Travis being dumb.

Remember, Travis checks your PR after it is merged into master, so if it detects an error that you don't have, make sure to merge the latest version of master into your branch. You can check unit tests by going to Window > Editor Test Runner in Unity.

When you fix your error, commit your changes as normal and Travis will retry the build.

You can also run the Travis script locally by running

$ ./Scripts/test.sh

from the command line. You cannot have the Unity editor open for this to work, however. If you get a complaint that it cannot find your Unity, find the Unity executable wherever you installed it on your system and run

$ export unityPath="/path/to/your/Unity.exe"

then try test.sh.

You can set test.sh to run automatically before pushing. This makes sure that you never push code that causes Travis builds to fail. To set this up run

$ cp Scripts/test.sh .git/hooks/pre-push

If tests are failing and for some reason you want to push anyway you can do git push --no-verify.

If your build failed due to Travis being dumb, then you don't have to change your code. Instead you can either continue pushing commits if you are still working, or simply close and reopen your PR. Either will cause Travis to rebuild your PR. Hopefully Travis will actually work the second time around.

For any further questions on Travis and CI Builds, ask @bjubes on the discord help channel.

Help! I added a file to my PR by accident!

Many people have been having this issue, so hopefully this section can solve your problems.

###Prevention The best way to avoid adding extra files to your pull request is to never add them to your commits. Before you create a commit, check what is going to be added by looking at what is checked off in your GUI.

GUI Staging Area

Uncheck files that you do not want to include before you commit, and they will never end up in your PR.

###Removing Files Warning! This is an advanced git feature, so it may be easier to start over again in a new PR for smaller changes.

If your PR has additional files already, you must locate the commit where the files were added and rebase your PR to remove them. Rebase is potentially destructive, so use care to follow this tutorial exactly. If you are unsure of how to rebase to fix your specific issue, don't hesitate to ask @bjubes in your PR. There is additionally documentation on the git rebase command and a section in the official git book on rewriting history for further guidance.

  1. Rebase is easiest to do in the command line, so lets open it.
    • On Windows open git bash by typing "git bash" into search or by right clicking inside the root of Project Porcupine and finding the git bash option in the context menu.
    • On mac, open Terminal.exe from spotlight.
  2. use the cd command to change directories until you are at the root of Project Porcupine.
  3. switch to your PR's branch by typing git checkout <feature-branch-name>
  4. type in git rebase -i HEAD~3, replacing "3" with the number of commits ago you added the files you need to remove.
  5. Vim will open a new file that will let you modify your previous commits. Vim is not very intuitive, so follow along carefully.
  • When vim opens, you cannot directly edit the text as if in a word processor like notepad. Instead you must first hit the a key to get into insertion mode. When you hit a, --INSERT-- will appear at the bottom left of the screen.

    Insert Mode in Vim

  • If you added files in a commit and want to delete that commit in its entirety, use the arrow keys to move the cursor to the line the commit is on and delete it. In this case I will delete Update GIT_TUTORIAL.

    Deleting a commit

  • If you added files in a commit and want to modify the commit, but not delete it entirely, change pick to e on that line.

    editing a commit

  1. Once you are done choosing which commits to delete or edit, hit esc to exit --INSERT-- mode. To save your changes type in :wq (this should appear on the bottom left as you type) and hit Enter. If you messed up, delete everything in the file to abort by holding down d until the file is only ~. Then save with :wq.

  2. If you deleted commits only, you are done! finalize your changes by committing git commit -m "remove extra files" and pushing git push -f. This will permanently delete the commits you selected in step 5. If you chose to edit commits, read on.

  3. When you save in Vim, the console will then tell you to how to proceed.

    Rebase edit

  4. Remove files by using the command git rm <filepath> and then type git rebase --continue when you are done. type :wq when the commit appears in vim.

10.keep removing, continuing, and saving the new commit until the rebase is done. Then go back to step 7.

###I have a mess on my hands!

Pretty flowchart for resolving a git mess, from http://ndpsoftware.com/git-cheatsheet.html