FAQ¶
- Git FAQ
- I get an “
ssh: Could not resolve hostname
” error when pushing/pulling - I didn’t specify a commit message, and now I’m in a screen I don’t know how to get out of
- Trying to do a
git pull upstream master
takes me to a screen saying “Merge branch…” - How can I recover an accidentally-deleted file?
- How do I fix a “corrupt object”?
- What does it mean when Git tells me my current branch is behind?
- What are unmerged files?
- How do I look at a previous version of a file I pushed to the git server?
- I get an “
- VM FAQ
This page contains a number of frequently asked questions on Git and on our Virtual Machine.
Git FAQ¶
I get an “ssh: Could not resolve hostname
” error when pushing/pulling¶
If you are using the VM and see an error like this:
ssh: Could not resolve hostname mit.cs.uchicago.edu: Temporary failure in name resolution
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
the most likely cause is that your VM is not connected to the network.
Check that the machine you’re running the VM on has Internet access (you can do this just by opening a browser outside the VM and going to any page). The VM relies on your machine’s Internet connection to reach the GitLab server so, if your machine doesn’t have Internet access, neither will your VM.
If your machine’s Internet access is working correctly, you should try to restart the VM’s networking. In the top right corner of your VM, there should be an icon with two arrows pointing in opposite directions:
Click on that icon. It should bring up a pull-down menu where one of the options should be “Enable Networking”. That option should have a check mark next to it. Click on it once to disable the VM’s network, and then click on “Enable Networking” again to enable it. This will restart the networking on your VM, and may solve the problem.
If you don’t see the icon with the two arrows, the window your VM is running on may be too small. Either resize the window or scroll horizontally until you can see the icon.
I didn’t specify a commit message, and now I’m in a screen I don’t know how to get out of¶
When you forget to specify the -m
option to the git commit
command, Git will
open a command-line text editor for you to specify a commit message. You will typically
end up in either the nano
text editor or the vim
text editor. While
you are welcome to learn how to use either editor (and use them to
type in more elaborate commit messages), here we will simply explain how to
exit the editor so you can specify the message using the -m
option.
If you see something like this at the bottom of the screen:
^G Get Help ^O Write Out ^W Where Is ^K Cut Text ^J Justify ^C Cur Pos ^Y Prev Page M-\ First Line M-W WhereIs Next
^X Exit ^R Read File ^\ Replace ^U Uncut Text ^T To Spell ^_ Go To Line ^V Next Page M-/ Last Line M-] To Bracket
You’re in the nano
editor. Just press Control-X to exit. You will
return to the shell, and this message will appear:
Aborting commit due to empty commit message.
This is normal. Just re-run git with the -m
option.
If you see something like this at the bottom of the screen:
"~/cmsc12100-aut-19-borja/.git/COMMIT_EDITMSG" 67L, 2572C
You’re in the vim
editor. Press Escape, and then type in the following:
:q!
And press Enter. As with nano
, you will exit into the shell and you will get a message
telling you the commit was aborted.
Trying to do a git pull upstream master
takes me to a screen saying “Merge branch…”¶
When you run git pull upstream master
you may be taken to a screen that
starts with something like this:
Merge branch 'master' of mit.cs.uchicago.edu:cmsc12100-aut-19/cmsc12100-aut-19
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
Doing a git pull upstream master
fetches the latest changes from
our upstream repository, and merges them into your repository.
This merge is done by wrapping up all of our latest changes into a new commit,
which must have some message. Because this commit was automatically created,
Git hasn’t yet given you a chance to specify what the message should
be, so it opens up a text editor for you to edit a message.
First, read our answer to the previous question to identify what editor you are using. Once you’ve done so, simply do the following:
- If you are using
nano
: Press Control+O (the letter, not 0 the number), then Enter to save the message. Then, press Control+X to exit. - If you are using
vim
: Press Escape and then type:wq
and press Enter.
Doing this will save the commit and will complete the pull operation.
How can I recover an accidentally-deleted file?¶
Let’s say you accidently deleted a file named something.py
. If that
file has been previously added and committed to your repository,
you can recover it by running this command:
git checkout -- something.py
How do I fix a “corrupt object”?¶
In some cases, running Git may result in errors that refer to a “corrupt object”.
A “corrupt object” or an “empty object” is typically caused when you forcibly stop your VM (e.g., by forcibly closing the window the VM is running in, without saving its state, or by forcibly shutting down your VM or your laptop). When working on a VM, it is important that you either save the VM state or perform an orderly shutdown of the VM when you’re done with it. Otherwise, your VM image could get corrupted (hence the “corrupt” and “empty” object issues).
If you are already encountering the “corrupt object” or “empty object”, there is unfortunately no easy fix. Fortunately, this issue seems to affect only Git’s internal data, not the files themselves. Your work is not lost, you just can’t commit/push the code because Git’s internal data is corrupted.
You will need to re-run the setup script to get a fresh copy of your repository:
cd
mv cmsc12100-aut-19-username cmsc12100-aut-19-username.broken
cs-setup-script cmsc12100-aut-19
(where username
should be replaced with your CNetID)
The cmsc12100-aut-19-username
directory will now contain the latest
version of the code that you pushed to the server. You will need to
copy the files that you modified since your last push from
cmsc12100-aut-19-username.broken
to cmsc12100-aut-19-username
.
If you want to be on the extra-safe side, you may want to re-install a fresh VM on your machine, in case the VM you’ve been using so far has become corrupted after an abrupt stop.
What does it mean when Git tells me my current branch is behind?¶
When trying to do a git push
, you may get the following error message:
To git@mit.cs.uchicago.edu:cmsc12100-aut-19/username.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@mit.cs.uchicago.edu:cmsc12100-aut-19/username.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
student@CS-Vbox:~/cmsc12100-aut-19-username/pa1$
This error means that there are commits on the server that you pushed from somewhere else, and did not pull to your current location. Before you can push, you need to pull those commits from the server:
git pull
To avoid this problem from happening in the future, it is generally
good practice to always run git pull
before you start working on your
code, to make sure you always have the latest version of the code from
the Git server.
What are unmerged files?¶
When running git, you may sometimes get an error message like this:
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use
'git add/rm <file>' as appropriate to mark resolution,
or use 'git commit -a'
This error message means that, at some point in the past, you did a
git pull
that included code that conflicted with the code on your
machine. This situation is called a merge conflict, and Git needs
you to resolve it manually, because it cannot tell whether you want
the code on the server or the code on your machine to take precedence.
You can run git status
to see what files need to be updated manually
(under “Unmerged paths”). If you open these file(s) with an editor,
you should see some parts of the file that look like this:
<<<<<<<
foobar
=======
foobaz
>>>>>>>
What Git is basically saying is “In one version, this line contained ‘foobar’, but in another version it contained ‘foobaz’, and I don’t know how to reconcile that difference”. You need to choose one of the two and determine which one you want to keep. If you wanted to keep foobar in the example above, you would replace everything above with foobar (i.e., remove the “<<<”, “===”, “>>>” lines too).
Once you’ve resolved these conflicts, just git add
the files and
commit as usual.
You may also want to check out this handy guide from GitHub. Please note that it explains merge conflicts in terms of Git “branches”, which you do not need to use in this course. For the purposes of reading this guide, you can think of your local repository as one branch and the copy in the Git server as the other branch.
How do I look at a previous version of a file I pushed to the git server?¶
Go to your project on https://mit.cs.uchicago.edu, and then click on “Commits” on the left bar. This will show you a list of all the commits you’ve pushed to the server. In each of them, there is a “Browse code” link that will allow you to see the state of the code at that precise commit.
VM FAQ¶
Why is the prompt student@cs-vm:~$:
?¶
The VM has a single user account on it called student
. CNetIDs are
not recognized by the VM (they are, however, recognized by the setup
script, which will access your Git repository associated with your
CNetID, which is why you will see a directory called
cmsc12100-aut-19-username
in your home directory after you run the
setup script).
My VM is really slow. Can I make it go faster?¶
If your VM is running slowly, try doing the following:
- Power down your VM all the way. If it’s closed and in a saved state, you’ll have to start it up, and then shut it down either from the Ubuntu power menu, or by closing the container window and choosing “Send the shutdown signal”, then clicking “Shut down” in the Ubuntu popup.
- With your VM entry selected, click on the yellow Settings gear in the VirtualBox window.
- Head to System > Motherboard. Allocate half of your Base Memory. Don’t touch anything else here.
- Head to System > Processor. Allocate half of your Processors (the slider should be at the border between green and red). Enable PAE/NX, if the option is available.
- Head to Display > Screen. Crank up Video Memory to the maximum - push the slider all the way to the right. Enable 3D Acceleration. If you are using a Windows or Mac, select “VBoxSVGA” as the Graphics Controller.
- Click OK
- Power the VM back up
The text on my VM is really small. How can I make it bigger?¶
If you have a very high resolution display, your VM may appear with very small (and hard to read text). Try doing the following:
- Close your VM by saving its state (you do not need to shut it down).
- With your VM entry selected, click on the yellow Settings gear in the VirtualBox window.
- Head to Display > Screen. Under Scale Factor, try setting the value to 175%.
- Click OK
- Start the VM again
If your text is still too small, repeat the above steps, and try incrementing the Scale Factor to 200%. If that’s still too small, try 225%, etc.