Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
space kobold
Oct 3, 2009


Right now I keep absolutely everything I do in its own feat/*, fix/*, test/*, or qa/* branch, then --no-ff merge it back into master when done to preserve detailed branch history. Eventually it's kicked out to a long running stable branch when it's ready to get a version stamped on it and released.

I think it's mostly because I like seeing pretty lines when I do `git log --graph --oneline`.

Adbot
ADBOT LOVES YOU

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
What's your favorite mergetool on linux? I've been using kdiff3, wondering if there's anything else I should check out.

necrotic
Aug 2, 2005
I owe my brother big time for this!

fletcher posted:

What's your favorite mergetool on linux? I've been using kdiff3, wondering if there's anything else I should check out.

p4merge is amazingly good.

comedyblissoption
Mar 15, 2006

wwb posted:

SVN is a very, very different model from perhaps a different era. If you want it to behave like git it sucks, just ask linus. On the flip side when you want git to behave like SVN that can also suck. Go figure.
You can use git like a better SVN. The only practical thing I can think of where SVN is superior is binary files.

wwb
Aug 17, 2004

The other thing one can do in SVN you can't quite do directly in git is check out parts of trees. We've got a few opsy things we run that way with SVN that would never work with git without a bit more doing.

If your version control is simple enough that you've got an effectively linear commit system with minimal branching than just about any modernish CVS system will work.

Edison was a dick
Apr 3, 2010

direct current :roboluv: only

wwb posted:

The other thing one can do in SVN you can't quite do directly in git is check out parts of trees. We've got a few opsy things we run that way with SVN that would never work with git without a bit more doing.

Yeah, if you want to do sparse checkout, it's a per repository clone option, and you have to do it before checking out, so it's a PITA.
http://phatblat.com/blog/2014/09/14/git-sparse-checkout/ seemed to be the best documentation I could find on getting it to work, since it wasn't very clear in the manpages from what I could find.

necrotic
Aug 2, 2005
I owe my brother big time for this!

Edison was a dick posted:

Yeah, if you want to do sparse checkout, it's a per repository clone option, and you have to do it before checking out, so it's a PITA.
http://phatblat.com/blog/2014/09/14/git-sparse-checkout/ seemed to be the best documentation I could find on getting it to work, since it wasn't very clear in the manpages from what I could find.

When you check out part of a tree in SVN you don't get the entire repository, though. This method you still fetch *everything*, but the checkout will only be that sub-tree. Semantically it will look the same, but if the point is to save space or bandwidth this won't help.

Sedro
Dec 31, 2008

necrotic posted:

When you check out part of a tree in SVN you don't get the entire repository, though. This method you still fetch *everything*, but the checkout will only be that sub-tree. Semantically it will look the same, but if the point is to save space or bandwidth this won't help.
Except an entire git repository is often much smaller than a single svn commit

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
That's very very dependent on what you're storing and how much history you have.

mobby_6kl
Aug 9, 2009

by Fluffdaddy
Has anyone used hgweb? I want to stick it (or something similar) on my web hosting to publish some of my coding projects as part of my resume/portfolio.

There's probably enough documentation to get it working, but I'm still not sure what I'll actually be getting. Will there be a nice web interface to look at? Would it be easy for someone to get my code? Would it be as usable as a local repo for me?

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS
Use BitBucket if you want hosted Mercurial repos.

MrPablo
Mar 21, 2003

mobby_6kl posted:

Has anyone used hgweb? I want to stick it (or something similar) on my web hosting to publish some of my coding projects as part of my resume/portfolio.

There's probably enough documentation to get it working, but I'm still not sure what I'll actually be getting. Will there be a nice web interface to look at? Would it be easy for someone to get my code? Would it be as usable as a local repo for me?

The hgweb/hgwebdir interface is themable. There are several built-in themes (including one that makes hgweb look like a gitweb repo), and the themes are relatively easy to fiddle with on your own. Yes, you can clone directly from hgwebdir URLs.

Supposedly you can configure hgweb to accept pushs as well, but I've never bothered, because it's easy to leave the web interface read-only and have separate push and pull paths for a clone:

code:
[paths]
~/hg/poop> cat .hg/hgrc 
default = httpZ://hg.butt.com/poop
default-push = ssh://hg.butt.com/hg/poop
(change the "httpZ" to "http" in the example URL above; the forums keep trying to helpfully wrap the URL).

MrPablo fucked around with this message at 02:48 on Nov 9, 2015

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


Just screwing around with Git, trying to learn more about administering a central repository for a small dev team. Got a couple questions-

- I've got an update hook that looks something like this (paraphrasing, wrong computer) to stop pushes to master:
code:
#!/bin/bash

ref=$1

if [ $ref == "refs/heads/master" ] && ([ -z $USER ] || [ $USER != "gitadmin" ]); then
  echo "Don't push to master! Push to develop and let Ciaphas know!" >&2
  exit 1
fi

exit 0
Since it's just a small dev team I don't expect anyone to be a butt and do something like env USER=gitadmin git push origin master, but just for curiosities' sake, is there a better way to do that without using any external packages? (I'm still trying to learn just git, without getting gitosis or gitolite or whatever involved)

- Say someone commits a couple times to master in their repo before realizing they're not supposed to push that. What's the 'right' way to fix this? I was thinking a rebase of some sort to get their commits onto their develop branch, delete their master branch, then push develop, but rebasing is still foreign loving witchcraft to me :saddowns:

- If a series of commits becomes unreachable--say by someone deleting an experimental branch without merging it anywhere--what happens to those commits? Do they just stay there taking up space and being mostly inaccessible forever?

(edit: just a background note, we're all coming off of ClearCase if that gives you any indication of how lost in the woods we collectively are :v:)

(edit) One more, kind of a policy question--is it typical to let finished topic branches sit around forever on the central repo once they're merged in to develop or wherever, or do you delete the branches for cleanliness' sake?

Ciaphas fucked around with this message at 18:34 on Nov 10, 2015

ToxicFrog
Apr 26, 2008


quote:

- Say someone commits a couple times to master in their repo before realizing they're not supposed to push that. What's the 'right' way to fix this? I was thinking a rebase of some sort to get their commits onto their develop branch, delete their master branch, then push develop, but rebasing is still foreign loving witchcraft to me :saddowns:

If they forgot to even start working on the feature branch, they can just rearrange the branch heads.

quote:

Start (but does not check out) a new branch named "feature" pointing to the current commit:
$ git branch feature

Rewind master to wherever it was upstream before this mistake:
$ git reset --hard origin/master

Resume work on the correct branch:
$ git checkout feature

If they made some commits on feature, then switched to master and made more commits that they meant to make on feature, a cherry-pick may be easier than a rebase:

quote:

Check out destination branch
$ git checkout feature

Cherry-pick commits from master onto feature branch; this will grab all commits made on master since the last update to origin/master. You can fine tune this, e.g. listing individual commit IDs.
$ git cherry-pick origin/master..master

Rewind master
$ git branch -f master origin/master


quote:

- If a series of commits becomes unreachable--say by someone deleting an experimental branch without merging it anywhere--what happens to those commits? Do they just stay there taking up space and being mostly inaccessible forever?

They stick around (and are reachable using the hash, which you can get with the reflog) for a while, but are eventually automatically cleaned up.

quote:

(edit) One more, kind of a policy question--is it typical to let finished topic branches sit around forever on the central repo once they're merged in to develop or wherever, or do you delete the branches for cleanliness' sake?

I delete the branches, but I don't know how universally true that is.

necrotic
Aug 2, 2005
I owe my brother big time for this!

ToxicFrog posted:

I delete the branches, but I don't know how universally true that is.

I believe its all over the place. For example, some people in my company delete branches after merging; others leave them around for ever! I recently went through and pruned a bunch of merged branches and killed off ~8k of them. But it doesn't really matter with how cheap branches are if you have a decent scheme for naming them.

brae
Feb 2, 2006
I delete stale branches in central repos occasionally so that git gc can delete commits that only occur in those branches.

mobby_6kl
Aug 9, 2009

by Fluffdaddy

Blinkz0rz posted:

Use BitBucket if you want hosted Mercurial repos.
Thanks, I'll look into this but for now hgweb seemed to be the path of least resistance.


MrPablo posted:

The hgweb/hgwebdir interface is themable. There are several built-in themes (including one that makes hgweb look like a gitweb repo), and the themes are relatively easy to fiddle with on your own. Yes, you can clone directly from hgwebdir URLs.

Supposedly you can configure hgweb to accept pushs as well, but I've never bothered, because it's easy to leave the web interface read-only and have separate push and pull paths for a clone:

code:
[paths]
~/hg/poop> cat .hg/hgrc 
default = httpZ://hg.butt.com/poop
default-push = ssh://hg.butt.com/hg/poop
(change the "httpZ" to "http" in the example URL above; the forums keep trying to helpfully wrap the URL).

Got this working with CGI. Not exactly how I'd like it, probably, but good enough. No push for me either so far, I just manually copied the relevant directories. By far the biggest problem is actually cleaning up my extremely unprofessional commit notes before this can be shown to anyone :)

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

mobby_6kl posted:

Thanks, I'll look into this but for now hgweb seemed to be the path of least resistance.

Wtf? Sign up for an account then start pushing code. It's not rocket science.

mobby_6kl
Aug 9, 2009

by Fluffdaddy

Blinkz0rz posted:

Wtf? Sign up for an account then start pushing code. It's not rocket science.

I want to host it myself :downs:

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

mobby_6kl posted:

I want to host it myself :downs:

that's silly, and not worth the trouble

wwb
Aug 17, 2004

I've got 2 large web farms running just about every stack imaginable. Almost enough skilled humans and more than enough monitoring services to look after and maintain these things properly. We still host all of our sources in bitbucket, it just isn't worth the care and feeding.

evensevenone
May 12, 2001
Glass is a solid.

Ciaphas posted:



- I've got an update hook that looks something like this (paraphrasing, wrong computer) to stop pushes to master:
code:

#!/bin/bash

ref=$1

if [ $ref == "refs/heads/master" ] && ([ -z $USER ] || [ $USER != "gitadmin" ]); then
  echo "Don't push to master! Push to develop and let Ciaphas know!" >&2
  exit 1
fi

exit 0
Since it's just a small dev team I don't expect anyone to be a butt and do something like env USER=gitadmin git push origin master, but just for curiosities' sake, is there a better way to do that without using any external packages? (I'm still trying to learn just git, without getting gitosis or gitolite or whatever involved)
You can put that hook on your central server as well. Then when they try to push they will get an error ("remote rejected....").
Its probably worth checking out gitolite, it's not too hard to configure and it saves you having to add full user accounts to your git server for everyone or messing with whatever git-shell is.

It also lets you set permissions like that without a million git hooks.

mobby_6kl
Aug 9, 2009

by Fluffdaddy
I know, its not based on some cost/benefit analysis, hence the downs smilie. But I already set up the whole site and want this to be part of it rather than going with an external service. But considering I only need this to show off a handful of hobby-level projects, it was very straightforward to get what I want. Maybe even easier/faster than signing up for bitbucket, it's literally one CGI script and one config file with a list of repositories.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

mobby_6kl posted:

I know, its not based on some cost/benefit analysis, hence the downs smilie. But I already set up the whole site and want this to be part of it rather than going with an external service. But considering I only need this to show off a handful of hobby-level projects, it was very straightforward to get what I want. Maybe even easier/faster than signing up for bitbucket, it's literally one CGI script and one config file with a list of repositories.

You are completely ignoring the ongoing maintenance going forward, backups, etc etc. Bitbucket is a no brainer dude!

SurgicalOntologist
Jun 17, 2004

As far as I can tell, this commit to git screwed up one of my personal repos: http://git.kaarsemaker.net/git/commit/33cfccbbf35a56e190b79bdec5c85457c952a021/

quote:

submodule: allow only certain protocols for submodule fetches
Some protocols (like git-remote-ext) can execute arbitrary
code found in the URL. The URLs that submodules use may come
from arbitrary sources (e.g., .gitmodules files in a remote
repository). Let's restrict submodules to fetching from a
known-good subset of protocols.

Note that we apply this restriction to all submodule
commands, whether the URL comes from .gitmodules or not.
This is more restrictive than we need to be; for example, in
the tests we run:

git submodule add ext::...

which should be trusted, as the URL comes directly from the
command line provided by the user. But doing it this way is
simpler, and makes it much less likely that we would miss a
case. And since such protocols should be an exception
(especially because nobody who clones from them will be able
to update the submodules!), it's not likely to inconvenience
anyone in practice.

Caveat: I don't understand submodules, and generally have no idea what I'm doing.

I have a personal repo of dotfiles that also includes as submodules all the git and hg repos that I would usually clone and use on a new machine or even just symlink one file from. This includes both git and hg repos, which I previously had accomplished by using git-remote-hg and the "hg::" transport. However, it now appears that transports cause some security risk and are disabled. I get this error when I try to update the submodule:

code:
fatal: transport 'hg' not allowed
However, cloning the same transport+url works fine. There may be some kind of whitelist? I'm not sure. But I also think I'm probably doing something wrong since no one else seems to be having this issue. It took quite a bit of hunting to trace it to this commit.

Anyone know anything about the whitelist? Or have some other workaround?

Edison was a dick
Apr 3, 2010

direct current :roboluv: only

SurgicalOntologist posted:

Anyone know anything about the whitelist? Or have some other workaround?

Put export GIT_ALLOW_PROTOCOL=file:git:http:https:ssh:hg somewhere in your site wide configuration, and find someone who complaining at will cause the git maintainers to do something about it.

SurgicalOntologist
Jun 17, 2004

Thanks!

Kobayashi
Aug 13, 2004

by Nyc_Tattoo

Edison was a dick posted:

Assuming you're running git from a command-line you can pass --date=$timestamp to the git commit command when you commit each revision.

From a while back, but thanks. I was able to do what I wanted by setting the GIT_AUTHOR_DATE and GIT_COMMITTER_DATE environment variables. Setting both timestamps allowed me to export my old wiki pages with proper timestamps all the way back to 2004!

Next I would like to merge this repository of legacy wiki pages into a newer repository of Markdown-based pages. All the files are plain text and neither repo has any branches. None of the filenames overlap. Ideally I would like the unified repo to appear as one unbroken history all the way back to the beginning. I saw this answer on Stack Overflow but there are a lot of answers and it talks about merging the newer repo into a subdirectory. I'd rather have it all mixed up together. Is there a way to do what I'm trying to do?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
git format-patch $initial-rev-hash --stdout > file; cd otherrepo; git am file

format-patch and a text editor (or sed) is rarely the most elegant way to do something, but is a viable solution to a pretty hilariously large number of git questions.

22 Eargesplitten
Oct 10, 2010



I just started using git recently. I think I broke something, but I'm not sure how. What I wanted to do was revert my local copy to an old known working version. What I did was git reset --hard (version hash). That version didn't work either, so I double-checked by going back to an even older version. Now the newer version is gone from the git log and my github. What did I do?

Thankfully, I copied a recent version of all of the files I've been working on to a different folder on my machine, but I really don't want to make this mistake again.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

22 Eargesplitten posted:

I just started using git recently. I think I broke something, but I'm not sure how. What I wanted to do was revert my local copy to an old known working version. What I did was git reset --hard (version hash). That version didn't work either, so I double-checked by going back to an even older version. Now the newer version is gone from the git log and my github. What did I do?

Thankfully, I copied a recent version of all of the files I've been working on to a different folder on my machine, but I really don't want to make this mistake again.

You moved the branch back to an earlier commit. Everything after that commit was "gone". You're basically saying "move the branch pointer back to this point".

You could have grabbed the later commit hash from the reflog and reset to it.

What you probably wanted to do was checkout the older commit, not reset to it.

New Yorp New Yorp fucked around with this message at 21:26 on Feb 2, 2016

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today
If you had more recent code on github and lost it, you must have force pushed. There's a reason git gives you scary warnings about doing that: it's almost never the correct thing to do.

22 Eargesplitten
Oct 10, 2010



I've been writing this post for about 15 minutes now as I keep thinking of new things.

It looks like I probably just didn't push the commit yesterday, and my commit before that only changed files in a subfolder, so at first I thought I had lost all of the commits on github. I was wrong, I reset back to the most recent commit locally and now I'm going to push to github. That was scary, but thankfully didn't actually break anything.

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today
One of the nice things about git is that it's difficult to actually lose data no matter what you do. Even if you're going around resetting and forcing left and right there's always the reflog until garbage collection occurs.

ToxicFrog
Apr 26, 2008


To expand on this somewhat, when you rewind the branch with "git reset", it changes what commit the branch name refers to -- but it doesn't actually destroy the commits that it no longer sees. They just aren't directly accessible. If you know the hash, you can do anything you like to them (git log, git checkout, create a new branch/tag at that commit, etc).

If you don't know the hash, git has a tool for finding that out: git reflog. This shows where the branch head used to be. Unlike git log, it doesn't rely on the commit info for this, but on a separate log of operations -- so it works across things like reset and rebase. That gets you the hash.

For example:
code:
## Let's look at recent commits.
$ git log --format="%h %<(16)%cr %s"
015a512 5 days ago       Make map name and map depth independent
b3eb0d3 12 days ago      Make Map a component rather than a class
716377f 13 days ago      Move game/mapgen into mapgen/dredmor

## I unwisely step away from the keyboard. My cat moves in for the kill.
$ git reset --hard HEAD~64
$ git log --format="%h %<(16)%cr %s"
56194b0 6 months ago     This is the stupidest bug
8aff742 6 months ago     Doors can now be opened by bumping into them. Can't be closed though.
f5fc4ba 6 months ago     Doors should block movement if closed

## Oh poo poo, I just lost half a year of work!
## reflog to the rescue:
$ git reflog master
56194b0 master@{0}: reset: moving to HEAD~64
015a512 master@{1}: commit: Make map name and map depth independent
b3eb0d3 master@{2}: commit: Make Map a component rather than a class

## You can use either the hash or the @-notation here:
$ git reset --hard 015a512
## or
$ git reset --hard master@{1}
## or even
$ git reset --hard master@{one-day-ago}

## Everything is wonderful again.
$ git log --format="%h %<(16)%cr %s"
015a512 5 days ago       Make map name and map depth independent
Unreachable commits will eventually be cleaned up, but the default settings are to prune them after one month of unreachability.

22 Eargesplitten
Oct 10, 2010



There's probably an answer out there for this, but I can't find it, I'm probably googling the wrong thing. I tried to commit without a message, and it gave a long message starting with

"# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Changes to be committed:"

Learn Git says to type my message in at the top, but it won't let me type anything. What am I doing wrong?

E: Thanks for the information in the last post.

Seashell Salesman
Aug 4, 2005

Holy wow! That "Literally A Person" sure is a cool and good poster. He's smart and witty and he smells like a pure mountain stream. I posted in his thread and I got a FANCY NEW AVATAR!!!!

22 Eargesplitten posted:

There's probably an answer out there for this, but I can't find it, I'm probably googling the wrong thing. I tried to commit without a message, and it gave a long message starting with

"# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Changes to be committed:"

Learn Git says to type my message in at the top, but it won't let me type anything. What am I doing wrong?

E: Thanks for the information in the last post.

How do you mean it won't let you type anything? Are you in vi in command mode and trying to edit?

22 Eargesplitten
Oct 10, 2010



I'm in Git Bash on windows and after that message came up, it won't respond to my typing. I did this the first time I tried to commit anything and just exited out and did it again correctly, but I'd like to know how to get out of it without doing that.

This is what I'm getting, with the list of files I'm committing underneath.

chutwig
May 28, 2001

BURLAP SATCHEL OF CRACKERJACKS

It's probably vim. Try hitting i to go into edit mode, type some stuff, then hit Escape to exit edit mode. Then type :wq (or :x), which you should see at the bottom of the terminal, and hit Enter to save and exit.

Adbot
ADBOT LOVES YOU

22 Eargesplitten
Oct 10, 2010



:wq did it, thanks.

Yet another question. My master branch on github is extremely messy. Is it possible to delete the contents for the current commit and push the new, cleaned up folder? I already branched the current version off in case I end up needing something from it.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply