Skip to content

cargo new can generate a better .gitignore file #2565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
deepak opened this issue Apr 13, 2016 · 5 comments
Closed

cargo new can generate a better .gitignore file #2565

deepak opened this issue Apr 13, 2016 · 5 comments

Comments

@deepak
Copy link

deepak commented Apr 13, 2016

running cargo new hello_world --bin --vcs git

generates a .gitignore file with

target

can we use something like https://github.com/github/gitignore/blob/master/Rust.gitignore ?

am using "cargo 0.9.0 (8fc3fd8 2016-02-29)" on OSX

@steveklabnik
Copy link
Member

This wouldn't be any different, all compiled files are in target?

Plus, it will add the .lock file if you leave off --bin.

On Wed, Apr 13, 2016 at 3:48 AM, Deepak Kannan [email protected]
wrote:

running cargo new hello_world --bin --vcs git

generates a .gitignore file with

target

can we use something like
https://github.com/github/gitignore/blob/master/Rust.gitignore ?

am using "cargo 0.9.0 (8fc3fd8
8fc3fd8
2016-02-29)" on OSX


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#2565

@deepak
Copy link
Author

deepak commented Apr 13, 2016

@steveklabnik ah ok. was not aware

Do you think it makes sense to change the generated .gitignore file to ?

# Generated by Cargo
/target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
# Cargo.lock

I should have mentioned before,
that I am a rust noob. am trying out rust for the first time.

Generally I always look at the github/gitignore repo
for a "standard" .gitignore file
hence this issue

@steveklabnik
Copy link
Member

apparently github also ate the second half of my reply, due to mail

but it also will put the Cargo.lock in or not based on if you pass --bin or not.

I would rather submit a PR to the gitignore project to fix it to be more like ours, personally. @alexcrichton what do you think?

@alexcrichton
Copy link
Member

Yeah I agree with @steveklabnik that these entries are at least not necessary:

# Compiled files
*.o
*.so
*.rlib
*.dll

# Executables
*.exe

(as they're all in the target directory). I also don't think the leading / on target is always wanted because you may have sub-projects in Cargo which have their own target directories. It's relatively rare to name a module target so those projects can always tweak the gitignore specially.

As for Cargo.lock, I like having documentation in .gitignore, but @steveklabnik is also right that we generate it appropriately based on whether we're a library or binary, so for a "one true gitignore" it should be fine to leave in with docs + a link (as it is now), but through Cargo we already take care of it.

So I guess, yes, I agree that we should probably send a PR to gitignore to remove the build artifacts, but otherwise seems like a good gitignore to me!

@alexcrichton
Copy link
Member

Closing as we probably don't need to make changes locally for now, but thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants