How to add multiple files to Git at the same time

2019-03-07 13:16发布

This will be my first git use. I have added new files ( a lot ) to the folder/project ( git local repository).

I went through online tutorials and forums and see i can do

     git commit -a

So i go to the base folder of the repository and do a

    sudo git commit -a

But then, some screens comes up and asks me to add a comment which i do. i do not know how to proceed or exit. I do not want to mess up so i did ctrl + Z and did not do anything.

Can you guys please outline the commands i need to use?

git commit -a 

and

git push?

标签: git push commit
8条回答
干净又极端
2楼-- · 2019-03-07 14:02

Use the git add command, followed by a list of space-separated file names, e.g.

git add <file-name-1> <file-name-2> <file-name-3>
查看更多
叛逆
3楼-- · 2019-03-07 14:06

You can also select multiple files like this

git add folder/subfolder/*

This will add all the files in the specified subfolder. Very useful when you edit a bunch of files but you just want to commit some of them...

查看更多
冷血范
4楼-- · 2019-03-07 14:06

If you want to stage and commit all your files on Github do the following;

git add -A
git commit -m "commit message"
git push origin master

查看更多
Summer. ? 凉城
5楼-- · 2019-03-07 14:12

When you change files or add a new ones in repository you first must stage them.

git add <file>

or if you want to stage all

git add .

By doing this you are telling to git what files you want in your next commit. Then you do:

git commit -m 'your message here'

You use

git push origin master

where origin is the remote repository branch and master is your local repository branch.

查看更多
Root(大扎)
6楼-- · 2019-03-07 14:13

To add all the changes you've made:

git add .

To commit them:

git commit -m "MY MESSAGE HERE" #-m is the message flag

You can put those steps together like this:

git commit -a -m "MY MESSAGE HERE"

To push your committed changes from your local repository to your remote repository:

git push origin master

You might have to type in your username/password for github after this. Here's a good primer on using git. A bit old, but it covers what's going on really well.

查看更多
再贱就再见
7楼-- · 2019-03-07 14:15

If you want to add multiple files in a given folder you can split them using {,}. This is awesome for not repeating long paths, e.g.

git add long/path/{file1,file2,...,filen}

Beware not to put spaces between the ,.

查看更多
登录 后发表回答