program story

Git에 동시에 여러 파일을 추가하는 방법

inputbox 2020. 9. 4. 07:23
반응형

Git에 동시에 여러 파일을 추가하는 방법


이것은 나의 첫 번째 자식 사용입니다. 폴더 / 프로젝트 (git 로컬 저장소)에 새 파일 (많이)을 추가했습니다.

온라인 튜토리얼과 포럼을 살펴 봤는데

     git commit -a

그래서 나는 저장소의 기본 폴더로 이동하여

    sudo git commit -a

그런데 어떤 화면이 나타나서 제가하는 댓글을 추가하라고합니다. 진행하거나 종료하는 방법을 모르겠습니다. 나는 엉망으로 만들고 싶지 않아서 ctrl + Z를하고 아무것도하지 않았습니다.

제가 사용해야하는 명령에 대해 설명해 주시겠습니까?

git commit -a 

git push?

모든 변경 사항을 추가하려면 :

git add .

커밋하려면 :

git commit -m "MY MESSAGE HERE" # -m은 메시지 플래그입니다.

이러한 단계를 다음과 같이 조합 할 수 있습니다.

git commit -a -m "MY MESSAGE HERE"

커밋 된 변경 사항을 로컬 저장소에서 원격 저장소로 푸시하려면 :

git push origin master

그 후에 github의 사용자 이름 / 암호를 입력해야 할 수도 있습니다. 다음은 git 사용에 대한 좋은 입문서입니다. 조금 오래되었지만 정말 잘 진행되고있는 것을 다룹니다.


git add명령 뒤에 공백으로 구분 된 파일 이름 목록을 사용합니다 . 예 :

git add <file-name-1> <file-name-2> <file-name-3>

이와 같은 여러 파일을 선택할 수도 있습니다.

git add folder/subfolder/*

이렇게하면 지정된 하위 폴더의 모든 파일이 추가됩니다. 여러 파일을 편집 할 때 매우 유용하지만 일부 파일을 커밋하고 싶을 때 ...


일부가 언급했듯이 가능한 방법은 git interactive staging을 사용하는 것입니다 . 확장자가 다른 파일이있을 때 유용합니다.

$ git add -i
           staged     unstaged path
  1:    unchanged        +0/-1 TODO
  2:    unchanged        +1/-1 index.html
  3:    unchanged        +5/-1 lib/simplegit.rb

*** Commands ***
  1: status     2: update      3: revert     4: add untracked
  5: patch      6: diff        7: quit       8: help
What now>

를 누르면 2다음 enter사용 가능한 파일의 목록을 얻을 것이다 추가 할 :

What now> 2
           staged     unstaged path
  1:    unchanged        +0/-1 TODO
  2:    unchanged        +1/-1 index.html
  3:    unchanged        +5/-1 lib/simplegit.rb
Update>>

Now you just have to insert the number of the files you want to add, so if we wanted to add TODO and index.html we would type 1,2

Update>> 1,2
           staged     unstaged path
* 1:    unchanged        +0/-1 TODO
* 2:    unchanged        +1/-1 index.html
  3:    unchanged        +5/-1 lib/simplegit.rb
Update>>

You see the * before the number? that means that the file was added.

Now imagine that you have 7 files and you want to add them all except the 7th? Sure we could type 1,2,3,4,5,6 but imagine instead of 7 we have 16, that would be quite cumbersome, the good thing we don't need to type them all because we can use ranges,by typing 1-6

Update>> 1-6
           staged     unstaged path
* 1:    unchanged        +0/-1 TODO
* 2:    unchanged        +1/-1 index.html
* 3:    unchanged        +5/-1 lib/simplegit.rb
* 4:    unchanged        +5/-1 file4.html
* 5:    unchanged        +5/-1 file5.html
* 6:    unchanged        +5/-1 file6.html
  7:    unchanged        +5/-1 file7.html
Update>>

We can even use multiple ranges, so if we want from 1 to 3 and from 5 to 7 we type 1-3, 5-7:

Update>> 1-3, 5-7
           staged     unstaged path
* 1:    unchanged        +0/-1 TODO
* 2:    unchanged        +1/-1 index.html
* 3:    unchanged        +5/-1 lib/simplegit.rb
  4:    unchanged        +5/-1 file4.html
* 5:    unchanged        +5/-1 file5.html
* 6:    unchanged        +5/-1 file6.html
* 7:    unchanged        +5/-1 file7.html
Update>>

We can also use this to unstage files, if we type -number, so if we wanted to unstage file number 1 we would type -1:

Update>> -1
           staged     unstaged path
  1:    unchanged        +0/-1 TODO
* 2:    unchanged        +1/-1 index.html
* 3:    unchanged        +5/-1 lib/simplegit.rb
  4:    unchanged        +5/-1 file4.html
* 5:    unchanged        +5/-1 file5.html
* 6:    unchanged        +5/-1 file6.html
* 7:    unchanged        +5/-1 file7.html
Update>>

And as you can imagine we can also unstage a range of files, so if we type -range all the files on that range would be unstaged. If we wanted to unstage all the files from 5 to 7 we would type -5-7:

Update>> -5-7
           staged     unstaged path
  1:    unchanged        +0/-1 TODO
* 2:    unchanged        +1/-1 index.html
* 3:    unchanged        +5/-1 lib/simplegit.rb
  4:    unchanged        +5/-1 file4.html
  5:    unchanged        +5/-1 file5.html
  6:    unchanged        +5/-1 file6.html
  7:    unchanged        +5/-1 file7.html
Update>>

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 ,.


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.


It sounds like git is launching your editor (probably vi) so that you can type a commit message. If you are not familiar with vi, it is easy to learn the basics. Alternatives are:

  • Use git commit -a -m "my first commit message" to specify the commit message on the command line (using this will not launch an editor)

  • Set the EDITOR environment variable to an editor that you are familiar with


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

참고URL : https://stackoverflow.com/questions/19576116/how-to-add-multiple-files-to-git-at-the-same-time

반응형